Vault7: CIA Hacking Tools Revealed
Navigation: » Latest version
Why POSIX Daemonization is Complicated
Here's how Stevens says you're supposed to Daemonize:
void daemonize(const char *cmd) {
if ((pid = fork()) < 0)
err_quit()
else if (pid != 0) /* parent */
exit(0)
/* child A */
setsid()
if ((pid = fork()) < 0)
err_quit()
else if (pid != 0) /* child A * /
exit(0)
/* child B (grandchild) */
do_daemon_stuff();
}
Most people have 2 questions about this code:
- Why fork twice?
- Why setsid() in the first child?