Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Get void vs scalar vs list con ...Abandon this program to run another (Berikutnya)
Functions for processes and process groups

Schedule a SIGALRM

Daftar Isi

  • alarm SECONDS

  • alarm

    Arranges to have a SIGALRM delivered to this process after thespecified number of wallclock seconds has elapsed. If SECONDS is notspecified, the value stored in $_ is used. (On some machines,unfortunately, the elapsed time may be up to one second less or morethan you specified because of how seconds are counted, and processscheduling may delay the delivery of the signal even further.)

    Only one timer may be counting at once. Each call disables theprevious timer, and an argument of 0 may be supplied to cancel theprevious timer without starting a new one. The returned value is theamount of time remaining on the previous timer.

    For delays of finer granularity than one second, the Time::HiRes module(from CPAN, and starting from Perl 5.8 part of the standarddistribution) provides ualarm(). You may also use Perl's four-argumentversion of select() leaving the first three arguments undefined, or youmight be able to use the syscall interface to access setitimer(2) ifyour system supports it. See perlfaq8 for details.

    It is usually a mistake to intermix alarm and sleep calls, becausesleep may be internally implemented on your system with alarm.

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

    1. eval {
    2. local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
    3. alarm $timeout;
    4. $nread = sysread SOCKET, $buffer, $size;
    5. alarm 0;
    6. };
    7. if ($@) {
    8. die unless $@ eq "alarm\n"; # propagate unexpected errors
    9. # timed out
    10. }
    11. else {
    12. # didn't
    13. }

    For more information see perlipc.

    Portability issues: alarm in perlport.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Get void vs scalar vs list con ...Abandon this program to run another (Berikutnya)