From: Eleanor McHugh Date: 2009-05-08T23:58:01+09:00 Subject: Re: how to find and close opened file descriptor On 8 May 2009, at 14:55, Oliver Peng wrote: > 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. You should probably describe how your parent process is opening these file descriptors as clearly it's not via objects in the IO hierarchy or they would be accessible in the child process. As a general rule though, if you have control over where and when the file descriptors are coming into play you can use the IO.for_fd(file_descriptor) method and store them in a *shudder* global variable or constant... OPEN_FILES = [] ... ... fd = some_method_that_opens_file_and_returns_descriptor OPEN_FILES << IO.for_fd(fd) ... ... Then in the spawned child process closing these would be as simple as: OPEN_FILES.each { |file| file.close } Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason