S
Sumedh
Hi all,
So, im trying to run shell commands through Java using the
Runtime.getRuntime().exec() facility.
Now, basically I need to run the same command with different arguments
several times over, like thousands of times. So I have the exec() call
in a for loop.
Now after about some time I get this error:
java.io.IOException: Too many open files
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:491)
at java.lang.Runtime.exec(Runtime.java:457)
Now, basically, knowing some unix, I know that ports opened by files
etc show up as file descriptors, and there must be some limit to how
many file descriptors can be opened at one time.
However, my shell command does not open any ports, and is basically a
perl script doing some parsing.
Also, after each command exec(), I do a process.waitFor(), so I ensure
that the process ends before I execute the loop again. (Assuming Java
does this correctly)
So, basically, is the communication between the Java Runtime and the
exec'd process opening so many ports/pipes between them? Im sure
there will be the basic input/output/error between the two programs.
Or, is the process not ending, and waitFor() not working, that several
processes are being exec'd at the same time?
Any ideas on what could be the problem? I've cross-posted to
comp.lang.java.programmers as well as comp.unix.questions, since im
not sure where the problem lies.
Thanks a lot for your answers/thoughts.
sumedh
So, im trying to run shell commands through Java using the
Runtime.getRuntime().exec() facility.
Now, basically I need to run the same command with different arguments
several times over, like thousands of times. So I have the exec() call
in a for loop.
Now after about some time I get this error:
java.io.IOException: Too many open files
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:491)
at java.lang.Runtime.exec(Runtime.java:457)
Now, basically, knowing some unix, I know that ports opened by files
etc show up as file descriptors, and there must be some limit to how
many file descriptors can be opened at one time.
However, my shell command does not open any ports, and is basically a
perl script doing some parsing.
Also, after each command exec(), I do a process.waitFor(), so I ensure
that the process ends before I execute the loop again. (Assuming Java
does this correctly)
So, basically, is the communication between the Java Runtime and the
exec'd process opening so many ports/pipes between them? Im sure
there will be the basic input/output/error between the two programs.
Or, is the process not ending, and waitFor() not working, that several
processes are being exec'd at the same time?
Any ideas on what could be the problem? I've cross-posted to
comp.lang.java.programmers as well as comp.unix.questions, since im
not sure where the problem lies.
Thanks a lot for your answers/thoughts.
sumedh