Syntax

alarm EXPR
alarm

Definition and Usage

Sets the “alarm,” causing the current process to receive a SIGALRM signal in EXPR seconds. If EXPR is omitted, the value of $_ is used instead. The actual time delay is not precise, since different systems implement the alarm functionality differently. The actual time may

be up to a second more or less than the requested value. You can only set one alarm timer at any one time. If a timer is already running and you make a new call to the alarm function, the alarm timer is reset to the new value. A running timer can be reset without setting a new timer by specifying a value of 0.

Returned Value

  • Integer, number of seconds remaining for previous timer.

Example

Here is the source code making use of alarm() function call.
    eval {
local $SIG{ALRM} = sub { die "alarmn" }; # NB: n required
alarm $timeout;
$nread = sysread SOCKET, $buffer, $size;
alarm 0;
};
if ($@) {
die unless $@ eq "alarmn"; # propagate unexpected errors
# timed out
}
else {
# didn't
}

What Do You Think on This ? Say Here