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: Chet Ramey
Subject: Re: how to make a non-interactive bash kill its children
Date: Tue, 24 May 2005 17:16:31 -0400

> 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

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@case.edu    http://tiswww.tis.case.edu/~chet/




reply via email to

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