Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Trap SIGTERM and kill running process
- X-seq: zsh-users 20095
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Trap SIGTERM and kill running process
- Date: Sun, 5 Apr 2015 09:32:39 -0700
- In-reply-to: <mfql13$qc5$1@ger.gmane.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <mfql13$qc5$1@ger.gmane.org>
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:
for sig in INT HUP TERM
do
trap "kill -$sig -$$" $sig
done
trap "kill -HUP -$$" EXIT
Messages sorted by:
Reverse Date,
Date,
Thread,
Author