Zsh Mailing List Archive
Messages sorted by:
Re: $PPID not updated when the PPID changes (parent killed)
- X-seq: zsh-workers 48882
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: $PPID not updated when the PPID changes (parent killed)
- Date: Tue, 18 May 2021 19:06:01 +0100
- Archived-at: <https://zsh.org/workers/48882>
- In-reply-to: <CAH+w=7bywj1X1fyPLgpmo_OoqBEN8PjEDxDeKP-tMR_O4g04tg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <20210516152418.GA39669@zira.vinc17.org> <CAH+w=7a3y6MjrPQWnPc1O0ESroLesZXwaQ-_AxJB5XRk7xDj2Q@mail.gmail.com> <20210517202608.GA3255290@zira.vinc17.org> <CAH+w=7bhsp71vazSJ_9Un1btb4mrxBgUciUg4zfGv15LeUfT1g@mail.gmail.com> <YKLttAsFd4bl9waS@fullerene.field.pennock-tech.net> <CAH+w=7bywj1X1fyPLgpmo_OoqBEN8PjEDxDeKP-tMR_O4g04tg@mail.gmail.com>
2021-05-17 16:15:24 -0700, Bart Schaefer:
> Indeed. I'm tempted to say
> Just as with $$, the value is updated only within a new shell
> that increases $SHLVL, and not in other subshells.
$ (SHLVL=0; zsh -c 'echo $SHLVL $$ $PPID; sleep 2; exec zsh -c "echo \$SHLVL \$$ \$PPID"' & sleep 1)
1 485756 485755
1 485756 302910
(where in that case 302910 is the pid of the systemd user's
session child subreaper, traditionally, one would get 1
$PPID, like $$ are set when the shell is initialised, just after
it had been executed.
In the example above, the same 485756 process executed zsh twice
and $$ and $PPID were set twice.
Because of the exec (and it would have been the same without
exec in a few contexts where zsh skips forks implicitly), $SHLVL
is not incremented (well it is decremented by the first zsh
before exec and incremented again by the second).
$SHLVL (a (t)csh thing IIRC, not handled by all shells) is the
number of shell *invocations* you need to exit before that logs
I would find it much clearer if we described $$/$PPID in
relation to shell invocation initialisation like POSIX does.
Messages sorted by: