Movatterモバイル変換


[0]ホーム

URL:


functions /alarm
(source,CPAN)
#alarm SECONDS
#alarm

Arranges to have a SIGALRM delivered to this process after the specified number of wallclock seconds has 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 or more than you specified because of how seconds are counted, and process scheduling may delay the delivery of the signal even further.)

Only one timer may be counting at once. Each call disables the previous timer, and an argument of0 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, theTime::HiRes module (from CPAN, and starting from Perl 5.8 part of the standard distribution) providesualarm. You may also use Perl's four-argument version ofselect leaving the first three arguments undefined, or you might be able to use thesyscall interface to accesssetitimer(2) if your system supports it. Seeperlfaq8 for details.

It is usually a mistake to intermixalarm andsleep calls, becausesleep may be internally implemented on your system withalarm.

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

eval {    local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required    alarm $timeout;    my $nread = sysread $socket, $buffer, $size;    alarm 0;};if ($@) {    die unless $@ eq "alarm\n";   # propagate unexpected errors    # timed out}else {    # didn't}

For more information seeperlipc.

Portability issues:"alarm" in perlport.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp