[Linux-disciples] perl parent vs. child vs. process group -- killing

Adam Rosi-Kessel adam at rosi-kessel.org
Tue Aug 10 10:14:53 EDT 2004


I want to kill the entire process group of a running perl program, except
the program itself (i.e., I want to kill all the forked children).

This can be done with 

    local $SIG{HUP} = 'IGNORE';
    kill HUP => -$$

This works fine so long as the perl program is run directly from the
command line.  When I write a short shell script:

    #!/bin/sh
    some_perl_program

The above code no longer works; apparently the process group is connected
to the parent and not the child.  killing getppid() doesn't work in this
case, though, because the $SIG{HUP} = 'IGNORE' doesn't apply to the
parent.

Can anyone on this list who understands ipc explain how to kill all
children without killing the program, whether or not the program is
running from the command line or from another shell script?

The other more obvious way would be to just kill the children rather
than trying to kill the entire process group; I do have the immediate
child's pid from fork(), but not the pids of the child's children.
killing just the child (at least in many case) doesn't kill the child's
children.  If the child's output is *not* redirecting to /dev/null, I
can do this; otherwise I can't.

I've also tried killing the negative child's process group-- kill HUP
=> -$child_pid, but this doesn't have any different effect.
-- 
Adam Kessel
http://adam.rosi-kessel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20040810/d13471dd/attachment.pgp


More information about the Linux-disciples mailing list