]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
b4ed7957 MK |
2 | .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk |
3 | .\" <mtk.manpages@gmail.com> | |
4 | .\" | |
5fbde956 | 5 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
b4ed7957 | 6 | .\" |
4c1c5274 | 7 | .TH pthread_sigmask 3 (date) "Linux man-pages (unreleased)" |
b4ed7957 MK |
8 | .SH NAME |
9 | pthread_sigmask \- examine and change mask of blocked signals | |
0a9455e8 AC |
10 | .SH LIBRARY |
11 | POSIX threads library | |
8fc3b2cf | 12 | .RI ( libpthread ", " \-lpthread ) |
b4ed7957 MK |
13 | .SH SYNOPSIS |
14 | .nf | |
15 | .B #include <signal.h> | |
f90f031e | 16 | .PP |
b4ed7957 MK |
17 | .BI "int pthread_sigmask(int " how ", const sigset_t *" set \ |
18 | ", sigset_t *" oldset ); | |
19 | .fi | |
68e4db0a | 20 | .PP |
d39ad78f | 21 | .RS -4 |
fc1d1e69 MK |
22 | Feature Test Macro Requirements for glibc (see |
23 | .BR feature_test_macros (7)): | |
d39ad78f | 24 | .RE |
68e4db0a | 25 | .PP |
fc1d1e69 | 26 | .BR pthread_sigmask (): |
9d2adbae | 27 | .nf |
5c10d2c5 | 28 | _POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500 |
9d2adbae | 29 | .fi |
b4ed7957 MK |
30 | .SH DESCRIPTION |
31 | The | |
32 | .BR pthread_sigmask () | |
33 | function is just like | |
34 | .BR sigprocmask (2), | |
35 | with the difference that its use in multithreaded programs | |
3196395a | 36 | is explicitly specified by POSIX.1. |
b4ed7957 | 37 | Other differences are noted in this page. |
847e0d88 | 38 | .PP |
b4ed7957 MK |
39 | For a description of the arguments and operation of this function, see |
40 | .BR sigprocmask (2). | |
41 | .SH RETURN VALUE | |
42 | On success, | |
43 | .BR pthread_sigmask () | |
44 | returns 0; | |
45 | on error, it returns an error number. | |
46 | .SH ERRORS | |
47 | See | |
48 | .BR sigprocmask (2). | |
21f80449 | 49 | .SH ATTRIBUTES |
f5104723 PH |
50 | For an explanation of the terms used in this section, see |
51 | .BR attributes (7). | |
52 | .TS | |
53 | allbox; | |
c466875e | 54 | lbx lb lb |
f5104723 PH |
55 | l l l. |
56 | Interface Attribute Value | |
57 | T{ | |
9e54434e BR |
58 | .na |
59 | .nh | |
21f80449 | 60 | .BR pthread_sigmask () |
f5104723 PH |
61 | T} Thread safety MT-Safe |
62 | .TE | |
3113c7f3 | 63 | .SH STANDARDS |
4131356c AC |
64 | POSIX.1-2008. |
65 | .SH HISTORY | |
66 | POSIX.1-2001. | |
b4ed7957 MK |
67 | .SH NOTES |
68 | A new thread inherits a copy of its creator's signal mask. | |
847e0d88 | 69 | .PP |
bce38798 MK |
70 | The glibc |
71 | .BR pthread_sigmask () | |
72 | function silently ignores attempts to block the two real-time signals that | |
73 | are used internally by the NPTL threading implementation. | |
74 | See | |
75 | .BR nptl (7) | |
76 | for details. | |
a14af333 | 77 | .SH EXAMPLES |
b4ed7957 MK |
78 | The program below blocks some signals in the main thread, |
79 | and then creates a dedicated thread to fetch those signals via | |
80 | .BR sigwait (3). | |
81 | The following shell session demonstrates its use: | |
847e0d88 | 82 | .PP |
b4ed7957 | 83 | .in +4n |
b8302363 | 84 | .EX |
b4ed7957 MK |
85 | .RB "$" " ./a.out &" |
86 | [1] 5423 | |
87 | .RB "$" " kill \-QUIT %1" | |
88 | Signal handling thread got signal 3 | |
89 | .RB "$" " kill \-USR1 %1" | |
90 | Signal handling thread got signal 10 | |
91 | .RB "$" " kill \-TERM %1" | |
92 | [1]+ Terminated ./a.out | |
b8302363 | 93 | .EE |
b4ed7957 MK |
94 | .in |
95 | .SS Program source | |
96 | \& | |
b0b6ab4e | 97 | .\" SRC BEGIN (pthread_sigmask.c) |
e7d0bb47 | 98 | .EX |
ad3868f0 | 99 | #include <errno.h> |
b4ed7957 | 100 | #include <pthread.h> |
ad3868f0 | 101 | #include <signal.h> |
b4ed7957 MK |
102 | #include <stdio.h> |
103 | #include <stdlib.h> | |
104 | #include <unistd.h> | |
fe5dba13 | 105 | \& |
b4ed7957 | 106 | /* Simple error handling functions */ |
fe5dba13 | 107 | \& |
d1a71985 | 108 | #define handle_error_en(en, msg) \e |
b4ed7957 | 109 | do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) |
fe5dba13 | 110 | \& |
b4ed7957 MK |
111 | static void * |
112 | sig_thread(void *arg) | |
113 | { | |
13f78d96 | 114 | sigset_t *set = arg; |
b4ed7957 | 115 | int s, sig; |
fe5dba13 | 116 | \& |
b4ed7957 MK |
117 | for (;;) { |
118 | s = sigwait(set, &sig); | |
119 | if (s != 0) | |
120 | handle_error_en(s, "sigwait"); | |
d1a71985 | 121 | printf("Signal handling thread got signal %d\en", sig); |
b4ed7957 MK |
122 | } |
123 | } | |
fe5dba13 | 124 | \& |
b4ed7957 | 125 | int |
f1e39c1e | 126 | main(void) |
b4ed7957 MK |
127 | { |
128 | pthread_t thread; | |
129 | sigset_t set; | |
130 | int s; | |
fe5dba13 | 131 | \& |
4a905b92 MK |
132 | /* Block SIGQUIT and SIGUSR1; other threads created by main() |
133 | will inherit a copy of the signal mask. */ | |
fe5dba13 | 134 | \& |
b4ed7957 MK |
135 | sigemptyset(&set); |
136 | sigaddset(&set, SIGQUIT); | |
137 | sigaddset(&set, SIGUSR1); | |
138 | s = pthread_sigmask(SIG_BLOCK, &set, NULL); | |
139 | if (s != 0) | |
140 | handle_error_en(s, "pthread_sigmask"); | |
fe5dba13 | 141 | \& |
a0303c05 | 142 | s = pthread_create(&thread, NULL, &sig_thread, &set); |
b4ed7957 MK |
143 | if (s != 0) |
144 | handle_error_en(s, "pthread_create"); | |
fe5dba13 | 145 | \& |
b4ed7957 | 146 | /* Main thread carries on to create other threads and/or do |
c6beb8a1 | 147 | other work. */ |
fe5dba13 | 148 | \& |
b4ed7957 MK |
149 | pause(); /* Dummy pause so we can test program */ |
150 | } | |
e7d0bb47 | 151 | .EE |
b0b6ab4e | 152 | .\" SRC END |
b4ed7957 MK |
153 | .SH SEE ALSO |
154 | .BR sigaction (2), | |
155 | .BR sigpending (2), | |
9e88dbc3 | 156 | .BR sigprocmask (2), |
96841f0e | 157 | .BR pthread_attr_setsigmask_np (3), |
b4ed7957 MK |
158 | .BR pthread_create (3), |
159 | .BR pthread_kill (3), | |
160 | .BR sigsetops (3), | |
161 | .BR pthreads (7), | |
162 | .BR signal (7) |