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

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


The daemon() function was not historically available in all flavors of Unix, so a lot of "portable" code doesn't use it. There's really no reason to roll your own recipe as long as all the target platforms you care about have daemon().


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


There is no daemon function in POSIX. It's a vendor extension. Thus anyone writing portable code simply writes their own.