Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Runtime.getRuntime.exec gets used up

2 views
Skip to first unread message

James Quintenz

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
I have a problem on a Java program. I have stripped it down to the
following skeleton program named Testexec.java. It calls an
executable file named make_info_file.bat. I have simplified
make_info_file.bat to have no contents. It can be recreated with
"touch make_info_file.bat; chmod 777 make_info_file.bat". The output
from the program is included below. More version details follow
below.

#############################################################################
### File: Testexec.java
#####################################################
#############################################################################

public class Testexec
{

static public void main(String args[])
{
for (int I = 0; I<32; I++)
doproc();
}

static void doproc()
{
try {
System.out.println("| Entering loop ");
Runtime r = Runtime.getRuntime();
System.out.println("|| Got Runtime: "+r);
Process p = r.exec("make_info_file.bat ");
System.out.println("||| Back from exec with process:
"+p);
p.waitFor();
System.out.println("|||| Back from exec");
p.destroy();
System.out.println("||||| P is destroyed");
}
catch (java.io.IOException e) {
System.out.println("Error4.16 "+e);
e.printStackTrace();
return;
}
catch (java.lang.InterruptedException e1) {
System.out.println("Error4.17 "+e1);
return;
}
}
}


#############################################################################
### output:
#################################################################
#############################################################################

# javac Testexec.java
# java Testexec 2>&1
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@123ef69
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@3b0e79
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@133541c
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@d70c51
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@69dae5
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@1a21dbc
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@4e28a2
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@14dab04
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@16aad8
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@2a6eda
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@1d3e8de
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@15d8447
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@978f90
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@526d9c
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@19a1efb
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@168115c
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@14bbf1f
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
java.io.IOException: Bad file number
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.forkAndExec(Compiled Code)
at java.lang.UNIXProcess.<init>(Compiled Code)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.execInternal(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at Testexec.doproc(Compiled Code)
at Testexec.main(Compiled Code)
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@1f0c23a
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
java.io.IOException: Bad file number
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.forkAndExec(Compiled Code)
at java.lang.UNIXProcess.<init>(Compiled Code)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.execInternal(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at Testexec.doproc(Compiled Code)
at Testexec.main(Compiled Code)
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
java.io.IOException: Bad file number
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.forkAndExec(Compiled Code)
at java.lang.UNIXProcess.<init>(Compiled Code)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.execInternal(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at Testexec.doproc(Compiled Code)
at Testexec.main(Compiled Code)
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
java.io.IOException: Bad file number
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.forkAndExec(Compiled Code)
at java.lang.UNIXProcess.<init>(Compiled Code)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.execInternal(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at java.lang.Runtime.exec(Compiled Code)
at Testexec.doproc(Compiled Code)
at Testexec.main(Compiled Code)
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
||| Back from exec with process: java.lang.UNIXProcess@15fa533
|||| Back from exec
||||| P is destroyed
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
| Entering loop
|| Got Runtime: java.lang.Runtime@101bd12
Error4.16 java.io.IOException: Bad file number
#

#############################################################################
### Other details and clues:
################################################
#############################################################################

The above output was obtained using my environment described in the
next paragraph. Another person tried it on Solaris 2.7 using
Java 1.2. He also had 17 good iterations and then failed, but with a
"libthread panic: _sys_thread_create():alloc_thread returns 0 (no mem)
(PID: 2830 1 LWP 1)
stacktrace:
         ff3679d0
... etc."
The exact error seems to be dependent on what is trying to get a scarce
resource first. I do not know what resource is in short supply or why
it is being consumed and how to prevent the consumption.

I compiled and ran my test case on a Sun Ultra 2 using Solaris
Version 2.5.1. This Solaris version is currently needed to run some
other applications. It was recommended to use Java 1.2. The
Java 1.2 version we are using is the beta version which was available
before Java 1.2 was released. The released Java 1.2 did not include
a version for Solaris 2.5.1, so we are still using the beta Java 1.2
version. The output listed above was obtained from a customized
Solaris system. However, the output on a generic Solaris 2.5.1
system is very similar. If the for loop count is increased, this
program will continue to run getting the "Bad file number" for a total
of around 110 iterations and then hang with no additional diagnostics.

Brian Crowley

unread,
May 20, 1999, 3:00:00 AM5/20/99
to
James Quintenz wrote:
>
> I have a problem on a Java program. I have stripped it down to the
> following skeleton program named Testexec.java. It calls an
> executable file named make_info_file.bat. I have simplified
> make_info_file.bat to have no contents. It can be recreated with
> "touch make_info_file.bat; chmod 777 make_info_file.bat". The output
> from the program is included below. More version details follow
> below...

You might be running into a file handle and/or memory limitation.
If you do a wait on each process you shouldn't run out of either.
If you don't want to do that you can try the runtime options to
set the size of the JVM so that it uses less memory and leaves
more available for other processes. The options are "-mx2M' and
"-ms2M" to start up the JVM at minimum size, I think.

Brian C.

Helen Buus

unread,
May 20, 1999, 3:00:00 AM5/20/99
to
Sounds to me like you're running out of file descriptors. The default
limit on Solaris is 64. With one fd for input and one fd for output per
iteration, plus 3 before you even start (System.in, System.out,
System.err), it's not surprising that a loop limit of 32 can't be
reached. Perhaps if you add the following after the waitFor() call,
you'll recover the fds:
p.getInputStream().close();
p.getOutputStream().close();
After reviewing the description of destroy() in Java in a Nutshell, I
don't think it's doing anything for you. destroy() should kill a
running process. By the time waitFor() returns, the process should
already be dead.

0 new messages