title: Why fork() twice while daemonizing?
body: <p>I'm wodering why people are calling <code>fork()</code> twice and why the 1st call is performed <em>before</em> <code>setsid()</code>.</p>
  
  <p>Yes, no new session is created if the caller is already a process group leader. But what if I just don't make the (grand)parent a process group leader? Who would make it for me (without asking me)? (OK, maybe 1llum1n4t1, Sc13nt0l0gy, the NSA, ... ;) )</p>
  
  <p>Yes, the 1st child should exit <em>immediately</em> not to create a zombie process. But couldn't the (grand)parent just exit after forking? Or would one or two <code>fprintf(stderr,...</code> or <code>write(2,...</code> calls (like "successfully started daemon xy") be such a <em>big deal</em>? (And couldn't I prevent zombies another way?)</p>
  
  <p>All in all, is this double-<code>fork()</code>-"magic" really <em>required</em> (not to get trouble)?
  Or is it just tradition or so-called "best practise" (like the avoiding of <code>goto</code>)?
  Or does it just guarantee the daemon to work on "historical" (of course I mean "far too old for usage in production environments") platforms like SVr4, BSD 3, RHEL 2 or some crappy, 32-bit embedded ones?</p>