get number of open files in a process?

Diane Bruce db at db.net
Fri Jan 22 14:41:12 UTC 2016


On Thu, Jan 21, 2016 at 11:51:11PM +0100, Mateusz Guzik wrote:
> On Thu, Jan 21, 2016 at 11:45:11PM +0100, Jilles Tjoelker wrote:
> > On Thu, Jan 21, 2016 at 07:44:01PM +0000, Batutis, Ed wrote:
...
> 
> This cannot work. POSIX mandates the lowest free fd is returned, so the
> N you see here can be extremely low, while the process is running out of
> fds.

The hack not mentioned here of course is to (mis-)use dup2() to shuffle
all your other fd's down by one as you close them. ;)

(This actually was used in early versions of the IRC Daemon. ;)
 Not for this reason however. )

> one to take - you have to have a very big reserve to not suddenly run
> out of fds, one would just limit amount of clients and, well, handle
> errors as they can pop up for reasons other than running out of fd slots.

I agree.

> 
> -- 
> Mateusz Guzik <mjguzik gmail.com>
> 

Diane
-- 
- db at FreeBSD.org db at db.net http://www.db.net/~db


More information about the freebsd-hackers mailing list