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

Re: kill the LHS command of a pipe once the RHS command terminates



On 2019-07-29 16:42:18 -0700, Bart Schaefer wrote:
> On Mon, Jul 29, 2019 at 4:15 PM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> >
> > zira% (trap '' INT; svn log | { (trap - INT; less;); kill -PIPE 0; })
> 
> This is fine, but note that "kill ... 0" sends the signal to the whole
> process group, which might have unexpected side-effects.

Yes, but I think that this is what I eventually expect. For instance,
if svn has started a ssh, then the ssh should be killed (whether it is
killed by svn or by the kill command above does not seem to matter).

BTW, this can be simplified to

  (trap '' INT; svn log | { (less); kill -PIPE 0 })

because

    ( list )
        Execute list in a subshell.  Traps set by the trap builtin are
        reset to their default values while executing list.

so no need to explicitly reset the INT trap to its default value.

> Bash and ksh93 manage process groups differently than zsh; this is
> related to the way zsh runs the right-hand-side of pipelines in the
> current shell when it can.
> 
> I don't know about dash or mksh, but but they must have more zsh-like
> group management.

Bash, dash and mksh execute both sides in a subshell, but not ksh93,
which behaves like zsh, well, with a difference that may be a bug in
zsh:

  { /bin/sleep 10 ; /bin/sleep 20; } | { /bin/sleep 30 ; /bin/sleep 40; }

can be interrupted by Ctrl-C in bash, dash, mksh and ksh93, but
not in zsh. But if I remove one of the sleep, this can also be
interrupted by Ctrl-C in zsh.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



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