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

Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups



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



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