alarm() and SIGALRM
Script started on Fri May 02 12:58:08 1997
sh-2.00$ cat alarm.c
/* alarm.c - demonstrate the SIGALRM signal and alarm system call */
void wakeup(int); /* executed when alarm received. */
void cleanup(int); /* Executed upon an abort. */
int counter = 0; /* Global so wakeup() and main() can both see it. */
void wakeup(int signum)
/* print the current value of counter */
printf("counter is currently %d.\n ",counter);
/* Set signal to this function. */
/* Set alarm clock for 5 seconds. */
void cleanup(int signum)
printf("Exiting after abort received.\n\n");
/* Illustrate catching interactive abort signals. */
signal(SIGINT, cleanup); /* Normally Delete key */
signal(SIGQUIT,cleanup); /* Normally ^\ */
/* Quietly count to ourselves but every 5 sec or so output
the counter. */
Fri May 2 12:58:50 CDT 1997
counter is currently 0.
Fri May 2 12:58:55 CDT 1997
counter is currently 76376094.
Fri May 2 12:59:00 CDT 1997
counter is currently 151521801.
Fri May 2 12:59:05 CDT 1997
counter is currently 226428907.
Exiting after abort received.
script done on Fri May 02 12:59:29 1997