1pthread_sigmask(3) Library Functions Manual pthread_sigmask(3)
2
3
4
6 pthread_sigmask - examine and change mask of blocked signals
7
9 POSIX threads library (libpthread, -lpthread)
10
12 #include <signal.h>
13
14 int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 pthread_sigmask():
19 _POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500
20
22 The pthread_sigmask() function is just like sigprocmask(2), with the
23 difference that its use in multithreaded programs is explicitly speci‐
24 fied by POSIX.1. Other differences are noted in this page.
25
26 For a description of the arguments and operation of this function, see
27 sigprocmask(2).
28
30 On success, pthread_sigmask() returns 0; on error, it returns an error
31 number.
32
34 See sigprocmask(2).
35
37 For an explanation of the terms used in this section, see at‐
38 tributes(7).
39
40 ┌────────────────────────────────────────────┬───────────────┬─────────┐
41 │Interface │ Attribute │ Value │
42 ├────────────────────────────────────────────┼───────────────┼─────────┤
43 │pthread_sigmask() │ Thread safety │ MT-Safe │
44 └────────────────────────────────────────────┴───────────────┴─────────┘
45
47 POSIX.1-2008.
48
50 POSIX.1-2001.
51
53 A new thread inherits a copy of its creator's signal mask.
54
55 The glibc pthread_sigmask() function silently ignores attempts to block
56 the two real-time signals that are used internally by the NPTL thread‐
57 ing implementation. See nptl(7) for details.
58
60 The program below blocks some signals in the main thread, and then cre‐
61 ates a dedicated thread to fetch those signals via sigwait(3). The
62 following shell session demonstrates its use:
63
64 $ ./a.out &
65 [1] 5423
66 $ kill -QUIT %1
67 Signal handling thread got signal 3
68 $ kill -USR1 %1
69 Signal handling thread got signal 10
70 $ kill -TERM %1
71 [1]+ Terminated ./a.out
72
73 Program source
74
75 #include <errno.h>
76 #include <pthread.h>
77 #include <signal.h>
78 #include <stdio.h>
79 #include <stdlib.h>
80 #include <unistd.h>
81
82 /* Simple error handling functions */
83
84 #define handle_error_en(en, msg) \
85 do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
86
87 static void *
88 sig_thread(void *