bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make a non-interactive bash kill its children


From: Irek Szczesniak
Subject: Re: how to make a non-interactive bash kill its children
Date: Tue, 24 May 2005 19:28:02 -0600
User-agent: Mozilla Thunderbird 1.0.2-1.3.3 (X11/20050513)

Thank you for your advice. It's really a nifty solution, and it works great for me!


Best,
Irek

Chet Ramey wrote:

I run a script, and so Bash runs non-interactively. In the script I run some commands with:

> some_command &

My script is run by a process which doesn't have a controlling terminal, and so my script doesn't inherit the terminal.

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

I'm assuming that you're running the script from a job control shell,
and that the process group of the jobs run from the script is the same
as the script's pid.  If that's the case, you should be able to do
something like:

        trap 'kill -s HUP -$$' 0

in the script as well.

Chet






reply via email to

[Prev in Thread] Current Thread [Next in Thread]