I'm wodering why people are calling fork()
twice and why the 1st call is performed before setsid()
.
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, ... ;) )
Yes, the 1st child should exit immediately not to create a zombie process. But couldn't the (grand)parent just exit after forking? Or would one or two fprintf(stderr,...
or write(2,...
calls (like "successfully started daemon xy") be such a big deal? (And couldn't I prevent zombies another way?)
All in all, is this double-fork()
-"magic" really required (not to get trouble)?
Or is it just tradition or so-called "best practise" (like the avoiding of goto
)?
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?