summaryrefslogtreecommitdiff
path: root/open_issues/alarm_setitimer/alrm.c
blob: 689020eea36b116260f22fbbc725726103aafdbf (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
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static const char msg[] = "< got alarm\n";

static void sighandler(int signo __attribute__((unused)))
{
  write(STDOUT_FILENO, msg, sizeof(msg) - 1);
}

int main()
{
  struct sigaction sa;
  sa.sa_handler = sighandler;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  if (sigaction(SIGALRM, &sa, NULL) == -1)
    return 1;

  printf("> alarm in 2 secs...\n");
  alarm(2);
  pause();

  printf("> alarm!\n");

  pause();
  printf("> got a signal...\n");

  return 0;
}