{ by david linsin }

February 21, 2007

Java's Runtime.exec() openes too many files

I had a stranger problem yesterday at work concerning Java's class java.lang.Runtime. I started processes in a loop on a Linux machine, using Runtime.exec method. After a calling it for a couple hundred times I get java.io.IOException with the message "Too many open files".

According to Mike Noel, what happens is, that Runtime.exec opens 2 java.io.InputStream instances and 1 java.io.OutputStream instance. If you don't close them manually using the java.lang.Process instance returned from Runtime.exec call, they hang forever. As far as I understand the message "Too many open files" is returned cause Linux uses file descriptors for sockets (please correct me if I'm wrong).


Anonymous said...

Nice tip, although I can't see any info from Sun on runtime.exec() having a 'close' option. How did you close those streams?


David Linsin said...

Well Runtime.exec returns an instance of java.lang.Process, which has methods to get the InputStream and OutputStream instances so that they can be closed.

see java.lang.Process

Anonymous said...

Thanks. That did the trick. I found some other documentation about process.destroy() closing all streams too. Apparently there was a problem prior to JRE 1.4 with p.destroy() killing the wrong linux process but that appears to be solved now according to sun's bug-track.


Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...



Timur taş Hoca

Anonymous said...

Aşçı Forum

Aşçı İş Arayanlar

Aşçı Arayanlar

Yerli Yemek Tarifleri

Aşçı Okulları

Dünya Global Mutfak

Profesyonel Yemek Malzemeleri

Profesyonel Sos çeşitleri

Tatlı Pasta Çeşitleri

Resturant Kurulumu

Yemek Üzerine İş yeri Kurulumu

Profesyonel Mutfak Malzemeleri

serkan said...

thanks for all information

bağcılar profilo servisi
bayrampaşa profilo servisi
bakırköy profilo servisi
avcılar ariston servisi
bağcılar ariston servisi
bahçelievler ariston servisi
bayrampaşa ariston servisi
beylikdüzü ariston servisi

Anonymous said...

Online Hack

Sinema Burda

Anonymous said...


Güncel koxp

pvp koxp

metin2 koxp

euko koxp

knightonline hile hack

Unknown said...

شركة مكافحة حشرات بالجبيل


  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)