On Thu, Feb 06, 2014 at 01:00:47AM +0200, Ion Savin wrote:
> From another terminal I kill the shell process:
>
> $ kill -9 `ps h --format pid -C "test.sh"`
>
> The shell process terminates but the child process is not killed.
This is because you're using SIGKILL (-9). You could arrange for
your script to catch any other signal and kill the child and then
itself. But SIGKILL can't be caught. SIGKILL therefore leaves
a bloody mess every time you use it -- temporary files will be strewn
about, child processes will be left running, etc.
Don't use SIGKILL unless it's a dire emergency, and even then, it's
often better to reboot the entire system instead.
(test.sh)
#!/usr/bin/env bash
trap 'kill $child; kill $$' TERM
eval "whatever" & child=$!
wait
(interactive shell)
$ pkill test.sh