-
Notifications
You must be signed in to change notification settings - Fork 0
/
ualarm_01.c
58 lines (46 loc) · 1.28 KB
/
ualarm_01.c
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
48
49
50
51
52
53
54
55
56
57
58
#define _GNU_SOURCE
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
void fct_alarm(int);
/* FCT_ALARM */
void fct_alarm(int signum)
{
printf("%s : received signal %d\n",
__func__, signum);
if ((signal(SIGALRM, fct_alarm)) == SIG_ERR) {
fprintf(stderr, "%s : signal returned an error !\n",
__func__);
exit(1);
}
}
/* MAIN */
int main(int argc, char *argv[])
{
sighandler_t _prev_sig;
useconds_t _time = 0, _interval = 0;
int _retcode = 0;
if (argc != 3) {
fprintf(stderr, "Usage: %s time_useconds interval_useconds\n", argv[0]);
exit(1);
}
_time = atol(argv[1]);
_interval = atol(argv[2]);
printf("Initializing ...\n");
if ((_prev_sig = signal(SIGALRM, fct_alarm)) == SIG_ERR) {
fprintf(stderr, "%s : signal returned an error !\n",
argv[0]);
exit(1);
}
if ((_retcode = ualarm(_time, _interval)) < 0) {
fprintf(stderr, "%s : ualarm returned %d !\n",
argv[0], _retcode);
perror("ualarm");
exit(1);
}
for (;;) {
pause();
}
return 0;
}