Search code examples
clinuxunixdaemonbsd

Is there a good reason to write my own daemonize function instead of using daemon(3)?


There are a lot of example implementations of daemons on the net. Most that I saw do not use the daemon(3) function to run the program in the background. Is that just a matter of taste, ignorance, or is there a good reason to write my own daemonize function? Is there a specific disadvantage in using daemon(3)? Is it insecure?


Solution

  • The BSD daemon() function is very limited and invites misuse. Only very few daemons may use this function correctly.

    The systemd man pages have a list of what a correctly written SysV daemon should do when daemonizing:

    http://0pointer.de/public/systemd-man/daemon.html