• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 static int sigalrm_received = 0;
5 
sigalrm_handler(int signr)6 static void sigalrm_handler(int signr)
7 {
8    sigalrm_received++;
9 }
10 
main(int argc,char * argv[])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;
18 
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 }
41