Home
Search Perl pages
Subjects
By activity
Professions, Sciences, Humanities, Business, ...
User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...
Text Strings
Conversions, tests, processing, manipulation,...
Math
Integer, Floating point, Matrix, Statistics, Boolean, ...
Processing
Algorithms, Memory, Process control, Debugging, ...
Stored Data
Data storage, Integrity, Encryption, Compression, ...
Communications
Networks, protocols, Interprocess, Remote, Client Server, ...
Hard World Timing, Calendar and Clock, Audio, Video, Printer, Controls...
File System
Management, Filtering, File & Directory access, Viewers, ...
|
|
|
alarm SECONDS
alarm
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.
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm $timeout;
$nread = sysread SOCKET, $buffer, $size;
alarm 0;
};
die if $@ && $@ ne "alarm\n"; # propagate errors
if ($@) {
# timed out
}
else {
# didn't
}
Source: Perl builtin functions Copyright: Larry Wall, et al. |
Next: atan2 Y,X
Previous: accept NEWSOCKET,GENERICSOCKET
(Corrections, notes, and links courtesy of RocketAware.com)
Up to: Process Signals and Events
Rapid-Links:
Search | About | Comments | Submit Path: RocketAware > Perl >
perlfunc/alarm.htm
RocketAware.com is a service of Mib Software Copyright 2000, Forrest J. Cavalier III. All Rights Reserved. We welcome submissions and comments
|