From owner-freebsd-java@FreeBSD.ORG Sun Mar 6 10:40:37 2005 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 74B1016A4CE for ; Sun, 6 Mar 2005 10:40:37 +0000 (GMT) Received: from lowrider.smega.com (lowrider.smega.com [82.149.226.102]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0AEB43D1F for ; Sun, 6 Mar 2005 10:40:36 +0000 (GMT) (envelope-from freebja@wie-ich.de) Received: from p5085938d.dip0.t-ipconnect.de ([80.133.147.141] helo=bubu) by lowrider.smega.com with asmtp (Exim 4.41 (FreeBSD)) id 1D7tBc-000Lu4-RO for freebsd-java@freebsd.org; Sun, 06 Mar 2005 11:40:37 +0100 Message-ID: <004801c52239$1d13e310$16b2a8c0@bubu> From: "Thomas Lange" To: Date: Sun, 6 Mar 2005 11:41:30 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Subject: Runtime.getRuntime().exec(...) -> Java process hangs in STOP state X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Mar 2005 10:40:37 -0000 Hi everyone, has anybody experienced a similar problem? I'm running tomcat with an apache / mod_jk frontend. After running a few days under medium load, a call of Runtime.getRuntime().exec(...) will not return. Also the Java process will hang infinitely in a STOP state (as displayed by top). As a result, mbufs or other resources will fill up until the entire server runs out of resources and hangs (creation of new processes is not possible anymore). I'm using FreeBSD 5.3-RELEASE-p5, jdk1.4, patchset 7. Everything (including the kernel) is compiled with -O2. Checking the output of my programm shows, that all processes created by it terminate correctly (that is, all but the last). In an ealier version (FreeBSD 4.9-RELEASE-p4), jdk1.4, patchset 6 there is a similar problem. Here calling Runtime.getRuntime().exec(...) results in creating a very high CPU load and not returning from the exec() call. My applications calls the exec()-method once every few minutes. Might it even be a threading issue? I've included a snippet from my program as an attachment. Any comments or suggestions are welcome! Regards Thomas public static boolean executeCommand(String exCommand, int exTimeout) { String command = "nice -n 15 "; command = command + exCommand; Process process = null; try { System.out.println("Executing external command " + command); process = Runtime.getRuntime().exec(command); } catch (IOException e) { System.out.println(e.toString()); return false; } InputStream inputStream = process.getInputStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); InputStream errorStream = process.getErrorStream(); BufferedInputStream bufferedErrorStream = new BufferedInputStream(errorStream); boolean ok = false; int timeout = exTimeout; int exitValue = -999; while (!ok) { try { while (bufferedInputStream.available() > 0 || bufferedErrorStream.available() > 0) { while (bufferedInputStream.available() > 0) { System.out.print((char)bufferedInputStream.read()); } while (bufferedErrorStream.available() > 0) { System.out.print((char)bufferedErrorStream.read()); } } } catch (IOException e) { System.out.println("Couldn't read response"); } try { exitValue = process.exitValue(); ok = true; } catch (IllegalThreadStateException e) { try { // still running. Thread.sleep(300); timeout = timeout - 300; if (timeout < 0 && timeout >= -300) { System.out.println("ALERT: Command doesn't terminate:"); System.out.println(command); System.out.println("Shutting down command..."); process.destroy(); } else if (timeout <0) { System.out.println("ALERT: Command STILL doesn't terminate:"); System.out.println(command); Thread.sleep(1000); } } catch (InterruptedException e1) { // doesn't matter } } } if (ok) { // finished running if (exitValue == 0) { System.out.println("Terminated without errors"); } else { System.out.println("Exit code " + exitValue + " while performing command " + command); } } else { process.destroy(); } try { while (bufferedInputStream.available() > 0) { System.out.print((char)bufferedInputStream.read()); } while (bufferedErrorStream.available() > 0) { System.out.print((char)bufferedErrorStream.read()); } } catch (IOException e) { System.out.println("Couldn't read response"); } return exitValue == 0; }