Sujet : Re: Why does getppid() still return old parent pid after setsid()?
De : Muttley (at) *nospam* DastartdlyHQ.org
Groupes : comp.unix.programmerDate : 11. Nov 2024, 11:02:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vgsko5$u7pg$1@dont-email.me>
References : 1 2
On Sat, 9 Nov 2024 09:25:22 -0000 (UTC)
gazelle@shell.xmission.com (Kenny McCormack) boring babbled:
In article <vgl8h1$385vs$1@dont-email.me>, <Muttley@DastartdlyHQ.org> wrote:
I've tried this code on both MacOS and Linux yet the child process getppid()
still returns its original parent process instead of "1" for init which is
what I'd expect. Isn't setsid() supposed to completely detach the child or
have I misunderstood?
>
I suppose the obvious question at this point is: Why do you care? What's
the underlying issue?
Just curiousity mainly. I did setsid() and ignored SIGCLD so I wouldn't get
zombie processes but noticed that getppid() didn't return 1. I'd forgotten
about double fork to be fair - I need to re-read Stevens at some point! - but
can't help thinking they should be a single shot OS call to completely
seperate the child from parent. Yes, daemon() will do it as a single function
call but I imagine that just does a double fork underneath anyway.
under Linux, there is also the re-parenting "prctl".
I didn't know that, thanks.