-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy path10.16.3.c
56 lines (45 loc) · 1.09 KB
/
10.16.3.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
#include "apue.h"
static volatile sig_atomic_t sigflag;
static sig_atomic_t newmask, oldmask, zeromask;
static void sig_usr(int signo) {
sigflag = 1;
}
void TELL_WAIT() {
if (signal(SIGUSR1, sig_usr) == SIG_ERR) {
err_sys("signal (SIGUSR1) error");
}
if (signal(SIGUSR2, sig_usr) == SIG_ERR) {
err_sys("signal (SIGUSR2) error");
}
sigemptyset(&zeromask);
sigemptyset(&newmask);
sigaddset(&newmask, SIGUSR1);
sigaddset(&newmask, SIGUSR2);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
err_sys("SIG_BLOCK error");
}
}
void TELL_PARENT(pid_t pid) {
kill(pid, SIGUSR2);
}
void WAIT_PARENT() {
while (sigflag == 0) {
sigsuspend(&zeromask);
}
sigflag = 0;
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
err_sys("SIG_SETMASK error");
}
}
void TELL_CHILD(pid_t pid) {
kill(pid, SIGUSR1);
}
void WAIT_CHILD() {
while (sigflag == 0) {
sigsuspend(&zeromask);
}
sigflag = 0;
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
err_sys("SIG_SETMASK error");
}
}