Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!pyrltd!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.questions Subject: Re: Starting a daemon (was: ... on a SVR3) Message-ID: <2570@root44.co.uk> Date: 7 Jan 91 17:48:30 GMT References: <25360@adm.brl.mil> <1752@dschub.dsc.com> <1991Jan03.132149.3565@scuzzy.in-berlin.de> Organization: UniSoft Ltd., London, England Lines: 19 src@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 (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273