summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/OR_USING_C/08.4.c
blob: 3bcc96cbb395678522a5918bf2b1f1d5eb9b3b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <signal.h>

main()
{
    /*
     * Declare handler routine so we can use its
     * name.
     */
    extern int handler();
    /*
     * Send signal to handler routine.  Only do so
     * if the signal is not already being ignored.
     */
    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
        signal(SIGINT, handler);
    /*
     * Loop here.
     */
    for (;;)
        pause();
}
/*
 * handler--handle the signal.  sig is the signal
 *           number which interrupted us.
 */
handler(sig)
int sig;
{
    /*
     * Users of 4.2 and 4.3BSD systems should un-comment
     * this line, which will make this program
     * behave as if it were on a non-Berkeley
     * system (we reset the signal by hand).
     */
    /* signal(sig, SIG_DFL); */
    /*
     * Ignore the signal for the duration of this
     * routine.
     */
    signal(sig, SIG_IGN);
    printf("OUCH\n");
    /*
     * Reset the signal to come here again.
     */
    signal(SIGINT, handler);
}