"java.io.IOException: Too many open files" rlim_fd_cur set to max

I am getting the "java.io.IOException: Too many open files" error when
running some program on a Solaris 8.  Pls note, I have already set
ulimit to max.  How can I avoid this problem?  Thanks in advance for
answering my question.

Here is the output from "uname -a":

SunOS ax-pb2 5.8 Generic_108528-19 sun4u sparc SUNW,Ultra-5_10

Here is what I have on the /etc/system:

set rlim_fd_cur = 4096
set rlim_fd_max = 4096
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please have a look at the following Sun Doc:

Document Audience: PUBLIC
Document ID: 3379
Title: Technote 3379
Synopsis: Too many open files thrown when Runtime.exec() is invoked
Update Date: Mon Mar 05 00:00:00 MST 2001


Document ID: 3379
Date Approved: 03/05/2001
Synopsis: Too many open files thrown when Runtime.exec() is invoked
OS Version: 8
IOException, Too many open files

I have encountered the following exception when I run the following program using Runtime.exec() on Solaris. How do I fix this problem? // ========= Exception Information ====== java.io.IOException: Too many open files 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 TestPro.run(Compiled Code) at TestPro.main(TestPro.java:29) // ========= My Program ============ public class TestPro{ Runtime runtime = null; Process p = null; int exitValue = -1; public TestPro(){ runtime = Runtime.getRuntime(); }; public void run() { try { while (true) { p = runtime.exec("echo"); java.lang.Thread.sleep(1000); p.waitFor(); } } catch(Exception e) { e.printStackTrace(); } } public static void main(String s[]) { TestPro tp = new TestPro(); tp.run(); } }
* The subprocess is not killed when there are no more references
 * to the <code>Process</code> object, but rather the subprocess
 * continues executing asynchronously.

This implies that a Process object can not be finalized. Also there is nothing
in the specification of waitFor() which implies that it is allowed to close the
I/O streams. The java code could read the process's output after it finishes.
Closing the process file descriptors should be done in the user code.

Add the following lines of code after calling p.waitFor();  


This should allow you to run the test code indefinitely.

Note that increasing the file descriptor limit in ulimit will only postpone
the occurrence of the problem.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.