"kill" group of commands from within script
From: Heiner Steven (heiner.steven_at_odn.de)
Date: 09/01/05
- Next message: Apostolos P. Tsompanopoulos: "Re: Ssh newbie question: publickey authentication method fails"
- Previous message: joe_at_invalid.address: "Re: TIMEZONE problem with TOUCH"
- Next in thread: Stefan Hirsch: "Re: "kill" group of commands from within script"
- Reply: Stefan Hirsch: "Re: "kill" group of commands from within script"
- Reply: Chris F.A. Johnson: "Re: "kill" group of commands from within script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 01 Sep 2005 16:08:19 +0200
I have a problem with a small shell script. It starts two
commands in the background, and then tries to terminate them
both using the kill(1) command:
==========(timeoutprob)==========
:
# Start process in the background
(sleep 10; echo WAKEUP) & bgpid=$!
sleep 1
# Terminate it
kill $bgpid
=================================
When I run this command using KornShell, the script works
as expected: the "kill" command in line 8 terminates the
background processes, i.e. both "sleep" and "echo".
Using BASH or Z Shell the "sleep" command gets inherited
by the "init" process (process id "1"), and continues running.
This results in many "sleep" processes running at a given time.
How can I write the script in a way that BASH terminates
the "sleep" command, too?
Background of the problem:
o (sleep 10; echo WAKEUP) &
creates more than one process:
(a) background process owning "sleep" and echo
(b) a process for "sleep"
(maybe another process for "echo").
Example:
pid process
1000 background process
1001 sleep
1002 echo
o the process id "bgpid" is always the one of the background
process (here: 1000)
When I now send SIGTERM to process 1000, ("kill 1000"), the
behaviour is different for KornShell on the one, and BASH/Z Shell
on the other hand.
o KornShell seems to send the signal to the process group,
effectively terminating all processes
o BASH/Z Shell send the signal to the parent of the group (here: 1000).
The children processes survive, and, having lost their parent,
are inherited by "init"
Does anybody have an idea how I could rewrite the script (without
touching BASH/Z Shell source code) for terminating the "sleep", too?
Heiner
-- ___ _ / __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de> \__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit |___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
- Next message: Apostolos P. Tsompanopoulos: "Re: Ssh newbie question: publickey authentication method fails"
- Previous message: joe_at_invalid.address: "Re: TIMEZONE problem with TOUCH"
- Next in thread: Stefan Hirsch: "Re: "kill" group of commands from within script"
- Reply: Stefan Hirsch: "Re: "kill" group of commands from within script"
- Reply: Chris F.A. Johnson: "Re: "kill" group of commands from within script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|