|
From: | Irek Szczesniak |
Subject: | Re: how to make a non-interactive bash kill its children |
Date: | Thu, 26 May 2005 09:47:29 -0600 |
User-agent: | Mozilla Thunderbird 1.0.2-1.3.3 (X11/20050513) |
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
[Prev in Thread] | Current Thread | [Next in Thread] |