rrucker has asked for the wisdom of the Perl Monks concerning the following question:
I want be able to call runtimed from different scripts, with different times and commands to execute.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 use the test script to call runtimed with a three-second alarm and a find command to execute.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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SIG{ALRM} Question
by Errto (Vicar) on Oct 29, 2005 at 21:31 UTC |