1 | #include <signal.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <string.h> |
5 | |
6 | int win = 0; |
7 | |
8 | static void |
9 | handler (int sig) |
10 | { |
11 | printf (format: "Received signal %d (%s).\n", sig, strsignal(sig: sig)); |
12 | win = 1; |
13 | } |
14 | |
15 | int |
16 | main (void) |
17 | { |
18 | if (signal (SIGTERM, handler: handler) == SIG_ERR) |
19 | { |
20 | perror ("signal: SIGTERM"); |
21 | exit (EXIT_FAILURE); |
22 | } |
23 | |
24 | puts (s: "Set handler."); |
25 | |
26 | printf (format: "Sending myself signal %d.\n", SIGTERM); |
27 | fflush (stdout); |
28 | |
29 | if (raise (SIGTERM) < 0) |
30 | { |
31 | perror ("raise: SIGTERM"); |
32 | exit (EXIT_FAILURE); |
33 | } |
34 | |
35 | if (!win) |
36 | { |
37 | puts (s: "Didn't get any signal. Test FAILED!"); |
38 | exit (EXIT_FAILURE); |
39 | } |
40 | |
41 | puts (s: "Got a signal. Test succeeded."); |
42 | |
43 | return EXIT_SUCCESS; |
44 | } |
45 |