From: Robert Klemme Date: 2004-09-15T20:19:54+09:00 Subject: Re: closing all open file descriptors "Ara.T.Howard" schrieb im Newsbeitrag news:Pine.LNX.4.60.0409141123490.29014@harp.ngdc.noaa.gov... > > i just discovered a subtle bugette (no harm done except nfs silly name > created) in some code i had written that is caused by forking with open file > descriptors followed by a close/unlink in the parent. the child never uses > the file and so it's not really an 'error' - but on nfs this will cause a > sillyname to appear (.nfsxxxxxxxx) and remain until the child exits which, in > this case, can be up to five days later and i have dozens of these guys > cluttering up my directories since this code runs on dozens of machine > simoutaneously. > > i'm wondering - is there some way in ruby to obtain the list of all open file > desriptors so that something akin to fdwalk might be used to close all open > descriptors > fileno(stderr). > > all i can think now is > > 3.upto(65536){|fd| IO::new(fd).close rescue nil} > > which is incredibly expensive! > > you could set the close on exec flag of all of them too - but getting the list > of all open fds is just as hard... ;-( Is it? >> ObjectSpace.each_object(IO) {|io| p [io, io.class, io.closed?]} [#, File, true] [#, File, true] [#, IO, false] [#, IO, false] [#, IO, false] [#, File, true] [#, File, true] [#, File, false] [#, File, true] => 9 Kind regards robert