Can we see the non-working code that uses alarm? This is a textbook example of when to use alarm.
Here, the alarm is triggered, and then processing continues:
alarm 5; $SIG{ALRM} = sub { print "alarm!\n" }; my $yawn = `sleep 10 ; echo "yawn"`; print "yawn? $yawn\n"; __END__ alarm! yawn? yawn
In this case (adapted from the example in the alarm documentation), the alarm is triggered, and processing is halted:
my $yawn; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 5; $yawn = `sleep 10 ; echo "yawn"`; alarm 0; }; print $@ ? 'Timed out.' : 'Finished.'; print "\n"; print "yawn? $yawn\n"; __END__ Timed out. yawn?
In reply to Re: How to timeout if a call to an external program takes too long
by kyle
in thread How to timeout if a call to an external program takes too long
by deivakumar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |