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-06 21:54:52 -0700, Bart Schaefer wrote:
> On Sat, Jul 6, 2019 at 4:56 PM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> >
> > On 2019-06-29 09:17:13 -0700, Bart Schaefer wrote:
> > >
> > > If you're going to kill the right-side with an interrupt or other
> > > signal, you'll have to arrange to trap that so that the subsequent
> > > kill isn't also skipped.
> >
> > but I would like to get rid of the job status that appear at the end.
> zsh% () {
> setopt localoptions nonotify nomonitor
> coproc { echo foo; exec >&-; sleep 60 }
> trap "kill $!" INT EXIT
> less -f <&p
> }

I've noticed 2 issues:

1. It can kill a wrong process of the coproc has terminated.
One needs to make sure that zsh does not wait for the coproc
until the function exits.

2. If the coproc is killed by the trap, I still get a notification.
With NOTIFY set globally, this happens during the trap, as I can
still see the notification with

  trap "kill $!; sleep 1" INT EXIT

before the 1-second delay from the sleep. A bug in localoptions,
which does not take traps into account?

If I unset NOTIFY globally, I get the notification just before
the prompt is displayed. But I don't think this is expected
either, as the child terminated when nomonitor was in effect.

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