daemon

APUEの中に書いてあるdaemonの書き方

More than 3 years have passed since last update.

Daemon Coding Rules

  1. call umask to set file mode creation mask.
  2. fork and have parent process exit.
    • 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
  3. 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
  4. chdir
  5. close files inherited from its parent
  6. redirect stdin, stdout, stderr to /dev/null