Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: $PPID not updated when the PPID changes (parent killed)

2021-05-17 18:27:00 -0400, Phil Pennock:
> On 2021-05-17 at 14:00 -0700, Bart Schaefer wrote:
> > Still mulling over possible rewording (at the very least change "for"
> > to "with" in that phrase).  Suggestions that don't try to explain unix
> > process hierarchy management in detail, are welcome.
> PPID <S>
>   The initial parent process ID; that is, the process ID of the process
>   which created this shell process, at the time that it did so.
>   Just as for $$, the value is only set for the original shell and does
>   not dynamically change for implicit subshells (as created for (list)
>   and for pipelines).

processes don't really create shell processes. A process may or
may  not fork itself, and then, maybe at a later point in
either the parent or the child (generally the child) execute a
shell (and generally, the parent will be waiting for that child).

For PPID, POSIX specification of sh says:

> Set by the shell to the decimal value of its parent process ID
> during initialization of the shell

Which is more accurate and clearer than any wording I can think
of. Note that by the time the shell "initialises" (where it
calls getppid() to fill in $PPID), the process that did fork the
process that executed the shell ($$) may alread be gone.

As in:

$ ( (sleep 1; exec zsh -c 'print $PPID') &)

I kind of agree with Vincent that it would be more useful if
$PPID reported the realtime value of the parent pid, but no
other shell does it and that would break POSIX compliance, and we
already have sysparam[ppid] as already noted.


Messages sorted by: Reverse Date, Date, Thread, Author