Chapter Contents |
Previous |
Next |
alarm, alarmd |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTION | |
PORTABILITY | |
EXAMPLE | |
SEE ALSO |
SYNOPSIS |
#include <lclib.h> unsigned int alarm(unsigned int sec); double alarmd(double sec);
The synopsis for the POSIX implementation is as follows:
#include <sys/types.h> #include <unistd.h> unsigned int alarm(unsigned int sec);
You may use either set of header files in your program.
DESCRIPTION |
alarm
and
alarmd
request that a SIGALRM signal
be generated after the number of seconds specified by its argument. Any previous
call to
alarm
or
alarmd
is canceled. If the argument to either of the alarm functions
is 0, any previous
alarm
or
alarmd
request is canceled, but no SIGALRM signal is generated. An
argument greater than a day (86400 seconds) is treated as a day.
alarmd
performs the
same actions as
alarm
but permits the amount
of time to be specified with greater accuracy. The accuracy of timing depends
on the operating system and CPU model.
RETURN VALUE |
The alarm functions return the number
of seconds remaining from any previous interval. (
alarm
rounds up to an integer of seconds.) If no interval is currently
active, 0 is returned.
CAUTION |
Under VM/SP and VM/HPO CMS, you must use
the CP command SET TIMER REAL for proper functioning of
alarm
and
alarmd
. If SET TIMER
REAL is not in effect, a diagnostic message is produced and a SIGALRM signal
is generated immediately.
If SIGALRM is handled by USS,
alarmd
is not available in releases of OS/390 prior to MVS 5.2.2..
PORTABILITY |
alarmd
is not portable.
EXAMPLE |
This example counts the number of divisions you can do in 5 seconds:
#include <lclib.h> #include <signal.h> #include <setjmp.h> #include <lcjmp.h> #include <stdio.h> void timeout(int signum); jmp_buf jbuf; volatile int i; int jcode; main() { /* Establish SIGALRM handling. */ onjmp(jbuf, jcode, done); signal(SIGALRM, &timeout); /* Perform calculations. */ alarm(5); for (i = 1; ; i++) { i/=1; sigchk(); } done: printf("%d divisions executed in 5 seconds.\n", i); return; } /* SIGALRM handler gets out of loop. */ void timeout(int signum) { longjmp(jbuf, 1); }
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.