Wei Weng 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...
---
Henrik Nordstrom