[Linux-disciples] Killing child processes in Perl
Stephen R Laniel
steve at laniels.org
Wed Jul 12 15:47:09 EDT 2006
On Wed, Jul 12, 2006 at 03:09:30PM -0400, Stephen R Laniel wrote:
> More specifically:
> http://perlmonks.com/?node_id=560791
>
> Very handy.
Here's my first pass at a function to digest the information
that system() gives back:
# run a subprocess, and kill the current one if
# the subproc caught some kind of nasty signal, if the
# subproc dumped core, etc.
sub system_with_kill {
system(@_);
my $command = join ' ', @_;
# See http://perldoc.perl.org/perlvar.html
if( $? != 0 ) { # if $? == 0, then all is well
my $retVal = ($? >> 8);
my $sigNum = ($? & 127);
my $thereWasACoreDump = $? & 128;
if( $thereWasACoreDump ) {
die "$command dumped core; closing parent pid $$";
}
if( $sigNum != 0 ) {
$sigName = getSigNameFromNum($sigNum);
if( ($sigName =~ m/KILL|INT/) ) {
die "$command caught SIG$sigName; closing parent pid $$";
}
}
}
}
--
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/9113c42c/attachment.pgp
More information about the Linux-disciples
mailing list