Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1374
  • Last Modified:

"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
1 Solution
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.


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now