Re: "kill" group of commands from within script
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 09/01/05
- Next message: Bill Marcum: "Re: Braces and variable visibility in ksh, and $?"
- Previous message: PM: "Re: BASH: how to change the default file type color"
- In reply to: Heiner Steven: ""kill" group of commands from within script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 1 Sep 2005 14:11:30 -0400
On 2005-09-01, Heiner Steven wrote:
> 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?
In bash, if you use the dynamically loadable builtin for sleep, it will
work.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
==================================================================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>
- Next message: Bill Marcum: "Re: Braces and variable visibility in ksh, and $?"
- Previous message: PM: "Re: BASH: how to change the default file type color"
- In reply to: Heiner Steven: ""kill" group of commands from within script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|