Alarm + Exec in Perl
Submitted by bj on Tue, 2009-09-01 13:18.
So if you call exec() from a sub called by SIGALRM, you need to unmask SIGALRM before calling the exec() or risk losing further alarms:
use POSIX qw(SIGALRM SIG_UNBLOCK sigprocmask);
...
sub handler {
my $sigset = POSIX::SigSet->new( &POSIX::SIGALRM );
sigprocmask(SIG_UNBLOCK, $sigset, undef);
...
exec([stuff]);
}
$SIG{ALRM} = \&handler;
Without the sigprocmask, your alarm will fire exactly once, be masked from running again, and your subsequent processes won't have an alarm to use anymore.
