Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot


by gods
on Aug 24, 1999 at 22:41 UTC ( #175=perlfunc: print w/ replies, xml ) Need Help??


See the current Perl documentation for alarm.


alarm - schedule a SIGALRM



Arranges to have a SIGALRM delivered to this process after the specified number of seconds have elapsed. If SECONDS is not specified, the value stored in $_ is used. (On some machines, unfortunately, the elapsed time may be up to one second less than you specified because of how seconds are counted.) Only one timer may be counting at once. Each call disables the previous timer, and an argument of 0 may be supplied to cancel the previous timer without starting a new one. The returned value is the amount of time remaining on the previous timer.

For delays of finer granularity than one second, you may use Perl's syscall() interface to access setitimer(2) if your system supports it, or else see select(). It is usually a mistake to intermix alarm() and sleep() calls.

If you want to use alarm() to time out a system call you need to use an eval()/die() pair. You can't rely on the alarm causing the system call to fail with $! set to EINTR because Perl sets up signal handlers to restart system calls on some systems. Using eval()/die() always works, modulo the caveats given in Signals.

    eval {
        alarm $timeout;
        $nread = sysread SOCKET, $buffer, $size;
        alarm 0;
    if ($@) {
        # timed out
    else {
        # didn't

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-12-27 07:34 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (176 votes), past polls