Hello,
I'm having a bit of a problem with using $SIG{ALRM} to kill a child process.
I wrote this script to take two arguments, alarm time and command to execute. The script is called runtimed:
my $status = 0;
my $maxTime = shift @ARGV;
my $runCmd = join ' ', @ARGV;
$SIG{ALRM} = sub { die "timeout" };
eval {
alarm($maxTime);
`$runCmd`;
alarm(0);
};
if ($@) {
if ($@ =~ /timeout/) {
local $SIG{'HUP'} = 'IGNORE';
kill('HUP', -$$);
$status = 1;
}
}
exit $status;
I want be able to call runtimed from different scripts, with different times and commands to execute.
Here's the test script I call it with:
my $FIND = '/usr/bin/find';
&finder($FIND, ' . -name somename -print');
sub finder {
my ($cmdName,$cmdOptions) = @_;
my $cmdExecute = $cmdName . $cmdOptions;
chdir "/";
my $res = `/usr/bin/perl runtimed 3 $cmdExecute`;
print "$res\n";
return 0;
}
I use the test script to call runtimed with a three-second alarm and a find command to execute.
The result I get is that the test script dies after three seconds, but the find command continues to run. If I hard-code the alarm time and the find command into runtimed and just execute that, it kills the find command.
I'm using Perl version 5.8.0 on Red Hat Linux 3.2.2-5. I've read about Perl "safe" signals and how those sometimes aren't able to break in and kill a child process. I don't think this is my problem, though, since I'm able to kill the find command if I hard-code it into runtimed.
Thanks for any help,
Ryan
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.