Henrik Nordstrom wrote: > > > if(fork()) > > > exit(0); > > > close(0); > > > open("/dev/null",O_RDONLY); > > > setsid(); > > > Question: > > why do u do open(...) here? > > thanks in advance. > > A stand-alone daemon should not have a terminal open as stdin, nor any > other source as stdin. Whis is why I close filedescriptor 0. > > The reason why I open /dev/null is to have something open on > filedescriptor 0. If I don't then then the first file the daemon opens > will get filedescriptor 0 which can have bad effects... There is a similar problem for descriptors 1 and 2, particularly in setuid programs. If a user runs the program with one or both of these descriptors closed, the next file which the program opens will get one of them. Any data written to stdout/stderr will then go to the file. -- Glynn Clements <[EMAIL PROTECTED]>