Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

alarm

Schedules a SIGALRM signal to be delivered after a given number of seconds.

Arranges for a SIGALRM to be delivered to the process after the specified number of seconds. If an alarm was already pending, the old alarm is cancelled and the number of seconds that were remaining is returned. Calling alarm(0) cancels the current alarm without setting a new one.

Commonly used with eval/die or $SIG{ALRM} to implement timeouts:

eval {
    local $SIG{ALRM} = sub { die "timeout\n" };
    alarm(10);
    # ... long operation ...
    alarm(0);
};

Negative values are clamped to 0.

Synopsis

my $remaining = alarm(30);   # fire SIGALRM in 30 seconds
alarm(0);                    # cancel any pending alarm

See Also

sleep, alarm, POSIX