Daniel Berger
5/8/2009 4:01:00 PM
On May 7, 9:54=A0am, Oliver Peng <oliver.p...@skywave.com> 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:
>
> =A0 =A0 =A03.upto(1023) do |fd|
> =A0 =A0 =A0 =A0 begin
> =A0 =A0 =A0 =A0 =A0 if io =3D IO::new(fd)
> =A0 =A0 =A0 =A0 =A0 =A0 io.close
> =A0 =A0 =A0 =A0 =A0 end
> =A0 =A0 =A0 =A0 rescue
> =A0 =A0 =A0 =A0 end
> =A0 =A0 =A0 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