Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] exec + builtin and traps
On Tue, 12 Sep 2017 12:39:19 +0200
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> On 2017-09-12 11:19:06 +0100, Peter Stephenson wrote:
> > On Tue, 12 Sep 2017 12:02:57 +0200
> > Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> > > For zsh 5.4.1, the zshbuiltins(1) man page says:
> > >
> > > exec [ -cl ] [ -a argv0 ] [ command [ arg ... ] ]
> > > Replace the current shell with command rather than forking.
> > > If command is a shell builtin command or a shell function,
> > > the shell executes it, then immediately exits.
> >
> > It means immediately after the command has finished executing, not while
> > it's executing.
> >
> > > #!/usr/bin/env zsh
> > >
> > > trap 'echo foo' USR1
> > >
> > > echo $$
> > > ( sleep 1; kill -USR1 $$ ) &
> > > exec eval sleep 2
> >
> > So in your case it's still exectuing the eval sleep 2.
>
> No, by default (with TRAPS_ASYNC unset), traps are run *after* the
> child process has exited:
True, but the *builtin* is an eval list, that only terminates when it
has executed an arbitrary set of other commands. The trap is executed
at the end of this list, before control returns back to eval. We are
not exec'ing sleep here, we are exec'ing eval, so there is time after
the *child* process is executed, as in the TRAPS_ASYNC doc you quote.
eval, unlike exec, is not an permanent handoff of control to the
following command.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author