Starting a daemon (was: ... on a SVR3)

Geoff Clare gwc at root.co.uk
Tue Jan 8 04:48:30 AEST 1991


src at scuzzy.in-berlin.de (Heiko Blume) writes:

>yes [if you have posix stuff]:

>    for ( i = 0 ; i < sysconf(_SC_OPEN_MAX) ; i++ )
>	close( i );

This code assumes that there is always a finite limit on the number of
open file descriptors per process.  On systems where there is no limit the
sysconf() call will return -1, and no file descriptors will be closed.

Unfortunately POSIX doesn't provide any means of finding out the highest
open fd number, so there is no really robust way of handling this situation.
The best I can come up with is to close all descriptors up to some arbitrary
high number (e.g. 256).

-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273



More information about the Comp.unix.questions mailing list