Daemon Coding Rules
- call
umask
to set file mode creation mask. -
fork
and have parent processexit
.
- When invoked as shell command, letting parent
exit
make the shell think the command is finished - ensure that the child process is not a process group leader. This is a prerequisite for
setsid
- call
setsid
- The child process will be the leader of the new process group
- The child process will be the leader of the new process session
- The child process will be detached from its controlling terminal
chdir
- close files inherited from its parent
- redirect stdin, stdout, stderr to
/dev/null