?
Solved

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

Posted on 2003-02-24
2
Medium Priority
?
584 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:psynnott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 200 total points
ID: 8011542
if your script generates output, it will hang when the pipe is filled-up, because you never read it from the other end.
you should use procb.getInputStream(), and read all output until it finish or redirect output to /dev/null or a log file, e.g.:

{"/bin/sh","-c","/opt/tomcat/webapps/inms/jsp/inmscheck.pl >/dev/null 2>&1"});
0
 

Author Comment

by:psynnott
ID: 8011651
Perfect.  Thankyou :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
New style of hardware planning for Microsoft Exchange server.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question