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

Re: using trap function to cleanup and exit?



>>>>> On April 10, 2022 Lawrence Velázquez <larryv@xxxxxxx> wrote:

> On Sun, Apr 10, 2022, at 12:30 PM, Greg Klanderman wrote:
>> With no traps of either type, should the child sleep remain after the
>> script is killed by a signal?

> Child processes are not automatically terminated if their parent
> dies.  In general you have to handle this yourself (for example,
> https://mywiki.wooledge.org/SignalTrap#When_is_the_signal_handled.3F).
> I don't know if zsh has some special sauce to streamline this, as
> I rarely write scripts that spawn long-running processes.

Thank you Larry, of course that link is describing bash, not zsh, and
it's not immediately clear if they do/should behave the same in this
regard.

It does say that if an external foreground command is executing in
bash, that signals will not be handled until the command terminates.

And so the workaround is to background the command, in which case that
command will not be killed when the script is killed.  This is fine,
because you have the ability to capture the PID when you background
it, and so can handle killing it if you so desire.

The zsh script I posted has a foreground sleep, which does not seem to
prevent a signal from being handled as described for bash.  But with a
foreground command you have no ability to handle killing it when you
die, so it would only make sense to me for zsh to do that.

I need to study this and what Bart wrote a bunch more, but
unfortunately will not be able to do so for at least another week.

thank you,
Greg




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