in reply to SIG{ALRM} Question
Update: One other thing I forgot to mention - your original code traps the output of the "find" command and then discards it (that's what happens when you use backquotes and don't do anything with the return value) whereas mine allows it to be printed, so adjust accordingly as needed.my $status = 0; my $maxTime = shift @ARGV; my $runCmd = join ' ', @ARGV; my $child_pid; $SIG{ALRM} = sub { die "timeout" }; eval { alarm($maxTime); unless ($child_pid = fork) { exec $runCmd; die "could not exec $runCmd: $!"; } wait; alarm(0); }; if ($@) { if ($@ =~ /timeout/) { local $SIG{'HUP'} = 'IGNORE'; kill('HUP', $child_pid); $status = 1; } } exit $status;
|
|---|