sewardj | b2572b5 | 2011-06-26 09:36:38 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <signal.h> |
| 3 | #include <unistd.h> |
| 4 | static int sigalrm_received = 0; |
| 5 | |
| 6 | static void sigalrm_handler(int signr) |
| 7 | { |
| 8 | sigalrm_received++; |
| 9 | } |
| 10 | |
| 11 | int main (int argc, char *argv[]) |
| 12 | { |
| 13 | struct sigaction sa; |
| 14 | fprintf(stderr, "starting ...\n"); |
| 15 | sa.sa_handler = sigalrm_handler; |
| 16 | sigemptyset(&sa.sa_mask); |
| 17 | sa.sa_flags = 0; |
sewardj | f5194b3 | 2011-07-04 22:00:41 +0000 | [diff] [blame] | 18 | |
sewardj | b2572b5 | 2011-06-26 09:36:38 +0000 | [diff] [blame] | 19 | if (sigaction (SIGALRM, &sa, NULL) != 0) |
| 20 | perror("sigaction"); |
| 21 | if (kill(getpid(), SIGALRM) != 0) |
| 22 | perror("kill 1"); |
| 23 | |
| 24 | if (sigalrm_received == 1) |
| 25 | fprintf (stderr, "ok: 1st SIGALRM received\n"); |
| 26 | else |
| 27 | fprintf (stderr, "wrong 1st: unexpected value %d sigalrm_received\n", |
| 28 | sigalrm_received); |
| 29 | |
| 30 | if (kill(getpid(), SIGALRM) != 0) |
| 31 | perror("kill 2"); |
| 32 | |
| 33 | if (sigalrm_received == 2) |
| 34 | fprintf (stderr, "ok: 2nd SIGALRM received\n"); |
| 35 | else |
| 36 | fprintf (stderr, "wrong 2nd: unexpected value %d sigalrm_received\n", |
| 37 | sigalrm_received); |
| 38 | |
| 39 | return 0; |
| 40 | } |