forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.11.c
55 lines (42 loc) · 1.01 KB
/
10.11.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
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
static void sig_quit(int);
int main(void)
{
sigset_t newmask, oldmask, pendmask;
if (signal(SIGQUIT, sig_quit) == SIG_ERR) {
printf("can't catch SIGQUIT\n");
exit(-1);
}
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
printf("SIG_BLOCK error\n");
exit(-1);
}
sleep(5);
if (sigpending(&pendmask) < 0) {
printf("sigpending error\n");
exit(-1);
}
if (sigismember(&pendmask, SIGQUIT)) {
printf("\nSIGQUIT pending\n");
exit(-1);
}
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
printf("SIG_SETMASK error\n");
exit(-1);
}
printf("SIGQUIT unblocked\n");
sleep(5);
return 0;
}
static void sig_quit(int signo)
{
printf("caught SIGQUIT\n");
if (signal(SIGQUIT, SIG_DFL) == SIG_ERR) {
printf("can't reset SIGQUIT");
exit(-1);
}
}