The semantics of a fork, followed by setsid, and another fork

Tags: •  • 

So I came across a piece of code that looked like this:

if (fork() != 0) exit(0); setsid(); if (fork() != 0) exit(0);

What each individual system call can easily be looked up and understood (well, maybe not setsid), but what the entire block of code is doing is not clear at all

…and I really can’t say I understand the mechanics of it all to explain myself. But this python code segment’s comments does a good job of what the entire block of code is trying to do—daemonize a process completely.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text.
  • Images can be added to this post.
  • You may use [inline:xx] tags to display uploaded files or images inline.
More information about formatting options