-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
68 lines (50 loc) · 1.52 KB
/
main.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
59
60
61
62
63
64
65
66
67
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "signal.h"
void alrm_signal_handler(int signum) {
SYSV_sighold(signum);
printf("catch SIGUSR1 %d for signal\n", signum);
SYSV_sigrelse(signum);
SYSV_signal(SIGUSR1, alrm_signal_handler);
}
void alrm_sigset_handler(int signum) {
printf("catch SIGUSR2 %d for sigset\n", signum);
}
int test_signal(void) {
printf("[TEST SIGNAL]\n");
int timer_count = 3, i;
timer_t tid1, tid2;
struct itimerspec its1, its2;
struct sigevent sev1, sev2;
SYSV_signal(SIGUSR1, alrm_signal_handler);
SYSV_sigset(SIGUSR2, alrm_sigset_handler);
sev1.sigev_notify = SIGEV_SIGNAL;
sev1.sigev_signo = SIGUSR1;
sev2.sigev_notify = SIGEV_SIGNAL;
sev2.sigev_signo = SIGUSR2;
timer_create(CLOCK_REALTIME, &sev1, &tid1);
timer_create(CLOCK_REALTIME, &sev2, &tid2);
its1.it_value.tv_sec = 0;
its1.it_value.tv_nsec = 1000000;
its1.it_interval.tv_sec = 0;
its1.it_interval.tv_nsec = 1000000;
its2.it_value.tv_sec = 0;
its2.it_value.tv_nsec = 1000000;
its2.it_interval.tv_sec = 0;
its2.it_interval.tv_nsec = 1000000;
timer_settime(tid1, 0, &its1, NULL);
timer_settime(tid2, 0, &its2, NULL);
for(i = 0; i < timer_count; i++) {
printf("count = %d\n", i);
SYSV_sigpause(SIGUSR1);
SYSV_sigpause(SIGUSR2);
}
return 1;
}
int main(void) {
printf("%s\n", test_signal() ? "OK" : "NG");
return 0;
}