

#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.
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.
The SIGALRM signal is asynchronous, so it is discovered only when a function is called or returns. For this reason, as well as because of competition from other users, the signal may take slightly longer than the specified amount of time to be generated.
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.
alarm rounds up to an integer of seconds.)
If no interval is currently active, 0 is returned.
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 OpenEdition, alarmd is not available.
alarmd is not portable.
#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);
}
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.