LoginSignup
0

More than 5 years have passed since last update.

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

Posted at

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0