Link to home
Start Free TrialLog in
Avatar of psynnott
psynnott

asked on

Runtime.getRuntime().exec() Processes FREEZE after 60 secs

Hi,
 
I have a link on a jsp page to start a perl script to ping servers.  The perl script looks at a table in the mysql db and gets the ip addresses.
 
Everything works fine if I start the perl script from a shell manually - it runs until i stop it.  But, if i use my link on the web page, the process ALWAYS freezes after 60 secs.  never 61, never less than 60, always 60.
 
The code for the jsp page that starts the perl script is:
 
===================
 
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="inms" uri="/WEB-INF/Tags.tld" %>
<jsp:include page="header.jsp"/>
<%
Process procb = null;
String txt = null;
   Process proca = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","ps -e | grep inmscheck.pl | grep -v grep | awk {'print $1'}"});
   BufferedReader input = new BufferedReader(new InputStreamReader(proca.getInputStream()));
   if ((txt=input.readLine()) != null) {
      %><inms:error msg="Daemon already running with PID:"/>
      <B><% out.println(txt);%></b><br>
      <a href="login2.jsp"><b>OK</b></a><%
   } else {
      procb = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","/opt/tomcat/webapps/inms/jsp/inmscheck.pl"});
      %><inms:ok msg="Daemon started"/>
      <a href="login2.jsp"><b>OK</b></a><%
   }
%>
<jsp:include page="footer.jsp"/>
 
===================
 
proca checks to see if the process is running before continuing - procb starts the perl script.  the <inms> tags are just my tags that put that messages in a nice table.
 
any ideas why it stops after 60 seconds when run like this?  is it something to do with linux and the way im starting the script?  is it automatically stopped after 60 secs?
 
I couldnt find anything on the net about this problem so I assume its something im doing wrong
 
Paul
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of psynnott
psynnott

ASKER

Perfect.  Thankyou :)