From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: $PPID not updated when the PPID changes (parent killed)
Date: Tue, 18 May 2021 21:25:07 -0700 [thread overview]
Message-ID: <CAH+w=7ZXFzko8gvJFnpp0PmvhkD+TFL+tTjmYSuHvoeTHc+k0Q@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Y449A49SpWUvRfGQ0_0njfAy9KR=NGKKhL+Eh3ats1Gw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 906 bytes --]
On Tue, May 18, 2021 at 7:53 AM Bart Schaefer <schaefer@brasslantern.com> wrote
>
> PPID is not a special variable.
Well, I have to take that back; it IS documented as special, but only
because it's readonly (which it also is in e.g. bash).
Anyway, as per Stephane Chazelas,
> POSIX specification of sh says:
>
> > Set by the shell to the decimal value of its parent process ID
> > during initialization of the shell
>
> [...] 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.
POSIX doesn't say whether it should be readonly, as far as I can tell.
It is not readonly when bash is invoked as "sh" but remains readonly
in zsh's sh emulation, which might be considered a bug.
So ... hopefully the attached patch addresses the assorted issues raised.
[-- Attachment #2: PPID.txt --]
[-- Type: text/plain, Size: 2403 bytes --]
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index dc28a45ae..b514eb072 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -654,10 +654,11 @@ Same as tt(#).
)
vindex($)
item(tt($) <S>)(
-The process ID of this shell. Note that this indicates the original
-shell started by invoking tt(zsh); all processes forked from the shells
-without executing a new program, such as subshells started by
-tt(LPAR())var(...)tt(RPAR()), substitute the same value.
+The process ID of this shell, set when the shell initializes. Processes
+forked from the shell without executing a new program, such as command
+substitutions and commands grouped with tt(LPAR())var(...)tt(RPAR()),
+are subshells that duplicate the current shell, and thus substitute the
+same value for tt($$) as their parent shell.
)
vindex(-)
item(tt(-) <S>)(
@@ -817,9 +818,9 @@ The operating system, as determined at compile time.
)
vindex(PPID)
item(tt(PPID) <S>)(
-The process ID of the parent of the shell. As for tt($$), the
-value indicates the parent of the original shell and does not
-change in subshells.
+The process ID of the parent of the shell, set when the shell initializes.
+As with tt($$), the value does not change in subshells created as a
+duplicate of the current shell.
)
vindex(PWD)
item(tt(PWD))(
diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst
index 7db4c0c84..564afac29 100644
--- a/Test/E03posix.ztst
+++ b/Test/E03posix.ztst
@@ -161,3 +161,6 @@ F:POSIX has neither math functions nor floating point
0f:Width of %s is computed in bytes not characters
F:This is considered a bugfix in zsh
>< Stéphane>
+
+ PPID=foo
+-f:PPID is not a readonly variable
diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo
index 8f525c576..399b6fe03 100644
--- a/Doc/Zsh/mod_system.yo
+++ b/Doc/Zsh/mod_system.yo
@@ -263,9 +263,9 @@ tt($$), which returns the process ID of the main shell process.
)
item(tt(ppid))(
vindex(ppid, sysparams)
-Returns the process ID of the parent of the current process, even in
-subshells. Compare tt($PPID), which returns the process ID of the parent
-of the main shell process.
+Returns the current process ID of the parent of the current process, even
+in subshells. Compare tt($PPID), which returns the process ID of the
+initial parent of the main shell process.
)
item(tt(procsubstpid))(
Returns the process ID of the last process started for process
next prev parent reply other threads:[~2021-05-19 4:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-16 15:24 Vincent Lefevre
2021-05-16 18:37 ` Bart Schaefer
2021-05-17 20:26 ` Vincent Lefevre
2021-05-17 21:00 ` Bart Schaefer
2021-05-17 22:27 ` Phil Pennock
2021-05-17 23:15 ` Bart Schaefer
2021-05-18 0:30 ` Phil Pennock
2021-05-18 1:14 ` Bart Schaefer
2021-05-18 8:28 ` Vincent Lefevre
2021-05-18 8:15 ` Vincent Lefevre
2021-05-18 14:53 ` Bart Schaefer
2021-05-19 4:25 ` Bart Schaefer [this message]
2021-07-18 23:10 ` Lawrence Velázquez
2021-05-18 15:18 ` Mikael Magnusson
2021-05-18 16:14 ` Peter Stephenson
2021-05-18 18:20 ` Bart Schaefer
2021-05-18 17:37 ` Martijn Dekker
2021-05-18 18:08 ` Bart Schaefer
2021-05-18 19:40 ` Martijn Dekker
2021-05-18 18:06 ` Stephane Chazelas
2021-05-18 18:12 ` Bart Schaefer
2021-05-18 18:50 ` $SHLVL origin (was: $PPID not updated when the PPID changes (parent killed)) Stephane Chazelas
2021-05-18 15:56 ` $PPID not updated when the PPID changes (parent killed) Stephane Chazelas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7ZXFzko8gvJFnpp0PmvhkD+TFL+tTjmYSuHvoeTHc+k0Q@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).