-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsig_queue_recv.cpp
More file actions
62 lines (52 loc) · 1.28 KB
/
sig_queue_recv.cpp
File metadata and controls
62 lines (52 loc) · 1.28 KB
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
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 由于glibc的bug,此处需要将gettid如下
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
void handler(int signo) {
if (signo == SIGINT) {
printf("%ld ", gettid());
printf("recv SIGINT signo=%d\n", signo);
} else if (signo == SIGRTMIN) {
printf("%ld ", gettid());
printf("recv SIGRTMIN signo=%d\n", signo);
} else if (signo == SIGUSR1) {
sigset_t s;
sigemptyset(&s);
sigaddset(&s, SIGINT);
sigaddset(&s, SIGRTMIN);
sigprocmask(SIG_UNBLOCK, &s, NULL);
printf("%ld ", gettid());
printf(" SIGUSR1 unblock signal.\n");
} else {
printf("%ld ", gettid());
printf("recv other signo=%d\n", signo);
}
return;
}
int main(int argc, char* argv[]) {
extern int errno;
pid_t pid = getpid();
printf("%d\n", pid);
struct sigaction act;
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigset_t s;
sigemptyset(&s);
sigaddset(&s, SIGINT);
sigaddset(&s, SIGRTMIN);
sigprocmask(SIG_BLOCK, &s, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGRTMIN, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
for( ; ; ) {
pause();
}
return 0;
}