2.3.5-7
[glibc.git] / manual / examples / sigh1.c
blob2c6e95b9c9b406dcaec0594320f1f612fe5be949
1 #include <signal.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 /* This flag controls termination of the main loop. */
6 volatile sig_atomic_t keep_going = 1;
8 /* The signal handler just clears the flag and re-enables itself. */
9 void
10 catch_alarm (int sig)
12 keep_going = 0;
13 signal (sig, catch_alarm);
16 void
17 do_stuff (void)
19 puts ("Doing stuff while waiting for alarm....");
22 int
23 main (void)
25 /* Establish a handler for SIGALRM signals. */
26 signal (SIGALRM, catch_alarm);
28 /* Set an alarm to go off in a little while. */
29 alarm (2);
31 /* Check the flag once in a while to see when to quit. */
32 while (keep_going)
33 do_stuff ();
35 return EXIT_SUCCESS;