-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy path10.16.c
40 lines (29 loc) · 835 Bytes
/
10.16.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
#include "apue.h"
static void sig_int(int);
int main() {
sigset_t newmask, oldmask, waitmask;
pr_mask("program start: ");
if (signal(SIGINT, sig_int) == SIG_ERR) {
err_sys("signal (SIGINT) error");
}
sigemptyset(&waitmask);
sigaddset(&waitmask, SIGUSR1);
sigemptyset(&newmask);
sigaddset(&newmask, SIGINT);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
err_sys("SIG_BLOCK error");
}
pr_mask("in critical region: ");
if (sigsuspend(&waitmask) != -1) {
err_sys("sigsuspend error");
}
pr_mask("after return from sigsuspend: ");
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
err_sys("SIG_SETMASK error");
}
pr_mask("program exit: ");
exit(0);
}
static void sig_int(int signo) {
pr_mask("\nin sig_int: ");
}