[Linux-disciples] Killing child processes in Perl
Stephen R Laniel
steve at laniels.org
Wed Jul 12 12:19:37 EDT 2006
I have a Perl script that invokes some subprocesses via
system(). When I hit Ctrl+C while one of the subprocesses is
executing, the subprocess dies but the master process keeps
going. So then the master process moves on to the next
system() call and executes that one. So I have to hit Ctrl+C
again and again.
I've done
my $pid = $$;
$SIG{'INT'} = sub { kill 9, $pid };
in the master process, but that doesn't work: %SIG gets
redefined in the subprocesses, so that SIGINT only gets sent
to the subprocesses and not to the master process. How do I
ensure that the master process traps all the signals for all
its subprocesses?
This seems to work, as a quick hack: put
$SIG{'INT'} = sub { kill -9, getppid() };
in each of the subscripts. getppid() gets the parent's
pid, and kill -9, getppid() kills it. But I'd prefer not to
have to add that to every subscript that the parent script
might call.
So is there any way to do something in the master script to
trap all signals to its subscripts?
--
Stephen R. Laniel
steve at laniels.org
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- 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/20060712/4426095a/attachment.pgp
More information about the Linux-disciples
mailing list