Chet Ramey wrote:
I want Bash to kill the commands that I run when my script exits. The
option "huponexit" doesn't work for me because Bash runs
non-interactively. How can I achieve my goal?
Since it's a script, all processes are in the same process group.
Depending on your system (most accept this), you could do something
like
trap 'kill -s HUP 0' 0
Thank you. I tried this on Linux, Mac OS X, and AIX. It works great.
This is a sample script:
> #!/bin/bash
> sleep 100 &
> sleep 4
> trap 'kill -s HUP 0' 0
It works great except the exit code is 129:
> ~ >./script.sh; echo $?
> Hangup
> 129
The improvement therefore is to catch the HUP signal like this:
> #!/bin/bash
> sleep 1h &
> sleep 4
> trap 'exit 0' HUP
> trap 'kill -s HUP 0' EXIT
Best,
Irek
_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash