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

Re: Trap SIGTERM and kill running process



* Bart Schaefer (Sun, 5 Apr 2015 09:32:39 -0700)
> On Apr 5,  8:34am, Thorsten Kampe wrote:
> } 
> } is it possible to trap SIGTERM and make sure that running processes 
> } in the script (like `sleep 100`) will also be killed?
> 
> You can "setopt MONITOR HUP" and then zsh will send HUP to all the
> jobs it has started whenever it exits, but that doesn't e.g. send the
> TERM signal when zsh receives TERM.
> 
> } I'd rather terminate the group in the trap handler.
> 
> You can pass a negative process ID to zsh's builtin "kill" to send a
> signal to the whole group (if supported by the OS).  So something
> like this seems to work, though I haven't tested thoroughly:

Thanks, I'll give it a try. My first attempt today was `kill 0` which 
according to the man page should kill the current process group. It 
worked in Bash and Z Shell but in Zsh I wasn't able to Ctrl-C a 
`while true` loop with that trap.

Thorsten



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