Becoming a daemon
A life as a daemon is not an easy life and requires a lot of gruesome deaths of parent processes.
The first thing needed for a process to become a daemon is to fork as a new process so the parent can exit, and the the prompt is returned to the invoking shell. This ensures that the new process is not a process group leader, since a process group leader cannot create a new session calling setsid. So, the new child process can now be promoted to process group leader and session leader by calling setsid. So far, the new session has no controlling terminal, and so does the new child. So, we fork again to be sure that the session and group leader can exit. Now, the grandchild is not a session, so the terminal it is going to open ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access