title: Process Builder waitFor() issue and Open file limitations
body: <p>I have inherited some code:</p>
  
  <pre><code>Process p = new ProcessBuilder("/bin/chmod", "777", path).start();
  p.waitFor();
  </code></pre>
  
  <p>Basically, there is for some ancient and highly voodoo based reason for storing key/value pairs on disk as files. I don't really want to go into it.</p>
  
  <p>However, I am left with a bunch of IO exceptions:</p>
  
  <pre><code>Exception :Cannot run program "/bin/chmod": java.io.IOException: error=24, Too many open files
  Message: Cannot run program "/bin/chmod": java.io.IOException: error=24, Too many open files
  </code></pre>
  
  <p>And by a bunch I mean in the realms of 10k - millions</p>
  
  <p>I get the feeling the waitFor call was to stop these from occurring waiting for the process to complete it and exit back, however I think the chmod is returning a result before the file is actually closed. Does anyone know if that would be the cause of these exceptions?</p>
  
  <p>My other inclination is that the opening and closing of thousands of files is not happening quickly enough on the java end and that there is something else going on, maybe something like that there is some form of file buffer that isn't getting cleared out when fw.close() is being called. </p>
  
  <p>I am pretty new to java and this was a hell weird one that has me stumped. (gladly the app still runs somehow.. after spitting out a very large log file that is)</p>
  
  <p>Can anyone else think of a way to get around this, clearing buffers or increasing the files open limit to something where the jvm can keep up with itself (assuming that is the problem)</p>