From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups
Date: Sun, 25 Mar 2018 08:00:53 +0100 [thread overview]
Message-ID: <20180325070053.GB5782@chaz.gmail.com> (raw)
In-Reply-To: <180324152357.ZM32580@torch.brasslantern.com>
2018-03-24 15:23:57 -0700, Bart Schaefer:
> On Mar 24, 5:34pm, Stephane Chazelas wrote:
> } Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components in diff
> }
> } Bart explained that it was because zsh uses the first spawned
> } process (here to run a builtin) for the process group, makes
> } other processes, that first process has already returned and has
> } been waited for so zsh can't make the other processes join the
> } foreground process group.
> }
> } I think here, zsh should not wait for that process until all the
> } processes in the jobs have been started and joined the process
> } group if that's what from a now-zombie process.
>
> That's going to require a lot of mucking about, because currently
> all process reaping is done in signal handlers. The shell only
> explicitly waits for the rightmost process in a pipeline. The
> SIGCHLD can't be blocked because then the exit of $(cat) in the
> second pipe step could not be captured, so the handler *will* be
> called when "echo" exits.
[...]
Note that the fact that in
a | b $(c) | D
The $(c) is done by the top-level process, that c is a child of
the top-level shell process as opposed to the process that will
eventually execute b is unique to zsh (and is complicating
things here).
That also causes some surprises like in
$ set +o multios
$ (sleep 1; echo A >&2) | echo B $(sleep 2) >&2 | echo C
A
B
C
("echo C" not started before "sleep 2" finishes) or:
Or (though some would find the zsh behaviour less surprising):
$ n=1; echo $((++n)) >&2 | echo $((++n)) >&2 | echo $n
2
3
3
(2, 2, 1 in any order in other shells)
See also:
$ set +o multios
$ echo A >&2 | echo $((+)) | echo B
A
zsh: bad math expression: operand expected at end of string
[1] done echo A >&2
"echo A" run but not "echo B" and message about a background
job returning.
$ sleep 10 | echo $((+)) | echo B
zsh: bad math expression: operand expected at end of string
$ jobs
[1] running sleep 10
$ fg
fg: no current job # fg %1 works
$
[1] done sleep 10
IIRC, that was discussed not so long ago on the austin-group
mailing list (which process should perform the expansions in
pipelines) though I didn't follow the discussion.
--
Stephane
next prev parent reply other threads:[~2018-03-25 7:01 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 16:16 Stephane Chazelas
2018-03-23 23:36 ` Bart Schaefer
2018-03-24 5:19 ` Bart Schaefer
2018-03-24 8:05 ` Joey Pabalinas
2018-03-24 17:34 ` Stephane Chazelas
2018-03-24 22:23 ` Bart Schaefer
2018-03-25 7:00 ` Stephane Chazelas [this message]
2018-03-25 8:26 ` Stephane Chazelas
2018-03-25 7:48 ` Stephane Chazelas
2018-03-25 18:09 ` Stephane Chazelas
2018-03-27 10:17 ` Stephane Chazelas
2018-03-24 22:09 ` Bart Schaefer
2018-04-10 11:45 ` Peter Stephenson
2018-04-10 13:59 ` Peter Stephenson
2018-04-11 22:10 ` Bart Schaefer
2018-04-12 16:23 ` Peter Stephenson
2018-04-15 16:23 ` Stephane Chazelas
2018-04-15 17:38 ` Bart Schaefer
2018-04-15 18:58 ` Stephane Chazelas
2018-04-17 5:39 ` Bart Schaefer
2018-04-17 9:19 ` Peter Stephenson
2018-04-17 16:09 ` Bart Schaefer
2018-04-17 16:27 ` Bart Schaefer
2018-04-17 16:35 ` Peter Stephenson
2018-04-17 17:52 ` Bart Schaefer
2018-04-19 9:40 ` Peter Stephenson
2018-04-20 9:28 ` Forking earlier for background code Peter Stephenson
2018-04-20 10:01 ` Peter Stephenson
2018-04-20 12:54 ` Vin Shelton
[not found] ` <CGME20180420132008eucas1p1c297624e870975cd892c74254970faab@eucas1p1.samsung.com>
2018-04-20 13:20 ` Peter Stephenson
2018-04-20 16:01 ` Vin Shelton
2018-04-23 8:29 ` Peter Stephenson
2018-05-01 9:23 ` Peter Stephenson
[not found] ` <F3A62E38-24E2-4A62-8E19-F54C9B81E9E5@kba.biglobe.ne.jp>
2018-04-23 13:52 ` "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups Peter Stephenson
2018-04-23 14:03 ` Peter Stephenson
[not found] ` <CGME20180423140859eucas1p2591bf1422614209979d4890383268c37@eucas1p2.samsung.com>
2018-04-23 14:08 ` Peter Stephenson
2018-04-23 15:29 ` Jun T.
2018-04-18 6:29 ` Stephane Chazelas
2018-04-18 16:33 ` Bart Schaefer
2018-04-10 9:53 ` Peter Stephenson
2018-03-25 7:38 ` 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=20180325070053.GB5782@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=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).