From: Oliver Peng Date: 2009-05-08T22:55:31+09:00 Subject: Re: how to find and close opened file descriptor Roger Pack wrote: >> And now I am assuming the maximum file no is 1023. Is there any way that >> I can get the maximum file no? > > You could run a loop at the beginning of your script which detects it :) > > count = 0 > all = [] > begin > loop { all << File.open('test','w') } > rescue Exception > count = all.length > for file in all do; file.close; end > end > count > > But getting back to your original question, another way to close > descriptors is > GC.each_object(IO) do |io| io.close; end > > I guess. Not totally sure what you mean by "doesnt create file > descriptors for each inherited object" ? > Thanks. > -=r At first, I also try to find all IO objects and close. Here is the code: ObjectSpace.each_object(IO) do |io| begin unless io.closed? io.close end rescue ::Exception end end But it doesn't work because ruby doesn't create IO object for the open file descriptor which are inherited from parent process. -- Posted via http://www.ruby-forum.com/.