Re: FD_CLFORK or equivalent?

Alexander Much (am293@cam.ac.uk)
Thu, 6 May 1999 19:03:30 +0100


Hi *!

> > struct rlimit *rlim;
> > if (getrlimit(RLIMIT_NOFILE, rlim)) { /* error */ }
> > fd = rlim->rlim_cur;
> > while (fd >=0 ) (void)close(fd--);
>
> This is how getdtablesize() in glibc works, and it is broken for at
> least one reason: You want to make that rlim_max, because a process
> could have opened (or inherited!) a fd and subsequently lowered
> rlim_cur. But by extension of that argument, even this is unreliable.
> Closing _really_ all file descriptors under any circumstances would
> require access to the maximum fd which _ever_ was allowed on the
> running system. This info is not available, not even via sysctl.
>
Even if it was available, this number could be very high on some
systems. Just imagine you have a 64bit number for the maximum and
start calling close() each time you decrease it...

Does someone know a portable way of doing it ?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/