--- name: alarm status: documented runtime: pp source: src/runtime/pp/process.rs --- ```{index} single: alarm; Perl built-in (pp runtime) ``` # alarm ## Synopsis ```perl my $remaining = alarm(30); # fire SIGALRM in 30 seconds alarm(0); # cancel any pending alarm ``` ## Description 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: ```perl eval { local $SIG{ALRM} = sub { die "timeout\n" }; alarm(10); # ... long operation ... alarm(0); }; ``` Negative values are clamped to 0. ## See also sleep, alarm, POSIX