Daemonizing question...

David K. Hess auvhess at auvc6.tamu.edu
Sat Feb 23 05:00:12 AEST 1991


Thanks to Jonathan Kamens and Xing Wu for the answer to this one. Due to
two requests for the answer I'm posting it here.

>	fork()
>	close(open descriptors)
>	open("/")
>	dup(0)
>	open("/dev/tty")
>	ioctl(tty,TIOCNOTTY)

The reason for the open("/") and dup(0) steps is so that any eventual
child process that might be fork()-exec()'d off has valid file
descriptors 0, 1, and 2 to play with and still not have a controlling
terminal. The reason "/" is used is historical. Apparently when the
daemonizing code was written "/dev/null" (a more likely candidate) was
not gauranteed to exist under all flavors of Unix (may still not for
all I know ;-).

Thanks for the help.

Dave Hess
Graduate Student
Texas A&M University
auvhess at auvsun1.tamu.edu



More information about the Comp.unix.wizards mailing list