From: Daniel Berger Date: 2009-05-09T01:01:01+09:00 Subject: Re: how to find and close opened file descriptor On May 7, 9:54 am, Oliver Peng wrote: > During my testing, I found that ruby doesn't create IO object for each > opened file descriptor which are inherited from parent process. So we > have to close all these opened file descriptor except stdin, stdout and > stderr by following way: > >      3.upto(1023) do |fd| >         begin >           if io = IO::new(fd) >             io.close >           end >         rescue >         end >       end > > But I really don't like this way. Is there better way that I can find > all opened file descriptors. > > And now I am assuming the maximum file no is 1023. Is there any way that > I can get the maximum file no? The io-extra library might be able to help you, depending on your platform. gem install io-extra. Take a look at the IO.closefrom and IO.fdwalk methods. Regards, Dan