Start of man-pages-5.14: renaming .Announce and .lsm files
[man-pages.git] / man2 / sigprocmask.2
blobb82386f141da3445a1a9b39db0c6cc745c5410ad
1 .\" Copyright (c) 2005 Michael Kerrisk
2 .\" based on earlier work by faith@cs.unc.edu and
3 .\" Mike Battersby <mib@deakin.edu.au>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" 2005-09-15, mtk, Created new page by splitting off from sigaction.2
28 .\"
29 .TH SIGPROCMASK 2 2021-03-22 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 sigprocmask, rt_sigprocmask \- examine and change blocked signals
32 .SH SYNOPSIS
33 .B #include <signal.h>
34 .PP
35 .nf
36 /* Prototype for the glibc wrapper function */
37 .BI "int sigprocmask(int " how ", const sigset_t *restrict " set ,
38 .BI "                sigset_t *restrict " oldset );
39 .PP
40 .BR "#include <signal.h>" "           /* Definition of " SIG_* " constants */"
41 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
42 .B #include <unistd.h>
43 .PP
44 /* Prototype for the underlying system call */
45 .BI "int syscall(SYS_rt_sigprocmask, int " how ", const kernel_sigset_t *" set ,
46 .BI "                kernel_sigset_t *" oldset ", size_t " sigsetsize );
47 .PP
48 /* Prototype for the legacy system call (deprecated) */
49 .BI "int syscall(SYS_sigprocmask, int " how ", const old_kernel_sigset_t *" set ,
50 .BI "                old_kernel_sigset_t *" oldset );
51 .fi
52 .PP
53 .RS -4
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
56 .RE
57 .PP
58 .BR sigprocmask ():
59 .nf
60     _POSIX_C_SOURCE
61 .fi
62 .SH DESCRIPTION
63 .BR sigprocmask ()
64 is used to fetch and/or change the signal mask of the calling thread.
65 The signal mask is the set of signals whose delivery is currently
66 blocked for the caller
67 (see also
68 .BR signal (7)
69 for more details).
70 .PP
71 The behavior of the call is dependent on the value of
72 .IR how ,
73 as follows.
74 .TP
75 .B SIG_BLOCK
76 The set of blocked signals is the union of the current set and the
77 .I set
78 argument.
79 .TP
80 .B SIG_UNBLOCK
81 The signals in
82 .I set
83 are removed from the current set of blocked signals.
84 It is permissible to attempt to unblock a signal which is not blocked.
85 .TP
86 .B SIG_SETMASK
87 The set of blocked signals is set to the argument
88 .IR set .
89 .PP
91 .I oldset
92 is non-NULL, the previous value of the signal mask is stored in
93 .IR oldset .
94 .PP
96 .I set
97 is NULL, then the signal mask is unchanged (i.e.,
98 .I how
99 is ignored),
100 but the current value of the signal mask is nevertheless returned in
101 .I oldset
102 (if it is not NULL).
104 A set of functions for modifying and inspecting variables of type
105 .I sigset_t
106 ("signal sets") is described in
107 .BR sigsetops (3).
109 The use of
110 .BR sigprocmask ()
111 is unspecified in a multithreaded process; see
112 .BR pthread_sigmask (3).
113 .SH RETURN VALUE
114 .BR sigprocmask ()
115 returns 0 on success.
116 On failure, \-1 is returned and
117 .I errno
118 is set to indicate the error.
119 .SH ERRORS
121 .B EFAULT
123 .I set
125 .I oldset
126 argument points outside the process's allocated address space.
128 .B EINVAL
129 Either the value specified in
130 .I how
131 was invalid or the kernel does not support the size passed in
132 .I sigsetsize.
133 .SH CONFORMING TO
134 POSIX.1-2001, POSIX.1-2008.
135 .SH NOTES
136 It is not possible to block
137 .BR SIGKILL " or " SIGSTOP .
138 Attempts to do so are silently ignored.
140 Each of the threads in a process has its own signal mask.
142 A child created via
143 .BR fork (2)
144 inherits a copy of its parent's signal mask;
145 the signal mask is preserved across
146 .BR execve (2).
149 .BR SIGBUS ,
150 .BR SIGFPE ,
151 .BR SIGILL ,
153 .B SIGSEGV
154 are generated
155 while they are blocked, the result is undefined,
156 unless the signal was generated by
157 .BR kill (2),
158 .BR sigqueue (3),
160 .BR raise (3).
163 .BR sigsetops (3)
164 for details on manipulating signal sets.
166 Note that it is permissible (although not very useful) to specify both
167 .I set
169 .I oldset
170 as NULL.
172 .SS C library/kernel differences
173 The kernel's definition of
174 .IR sigset_t
175 differs in size from that used
176 by the C library.
177 In this manual page, the former is referred to as
178 .I kernel_sigset_t
179 (it is nevertheless named
180 .I sigset_t
181 in the kernel sources).
183 The glibc wrapper function for
184 .BR sigprocmask ()
185 silently ignores attempts to block the two real-time signals that
186 are used internally by the NPTL threading implementation.
188 .BR nptl (7)
189 for details.
191 The original Linux system call was named
192 .BR sigprocmask ().
193 However, with the addition of real-time signals in Linux 2.2,
194 the fixed-size, 32-bit
195 .IR sigset_t
196 (referred to as
197 .IR old_kernel_sigset_t
198 in this manual page)
199 type supported by that system call was no longer fit for purpose.
200 Consequently, a new system call,
201 .BR rt_sigprocmask (),
202 was added to support an enlarged
203 .IR sigset_t
204 type
205 (referred to as
206 .IR kernel_sigset_t
207 in this manual page).
208 The new system call takes a fourth argument,
209 .IR "size_t sigsetsize" ,
210 which specifies the size in bytes of the signal sets in
211 .IR set
213 .IR oldset .
214 This argument is currently required to have a fixed architecture specific value
215 (equal to
216 .IR sizeof(kernel_sigset_t) ).
217 .\" sizeof(kernel_sigset_t) == _NSIG / 8,
218 .\" which equals to 8 on most architectures, but e.g. on MIPS it's 16.
220 The glibc
221 .BR sigprocmask ()
222 wrapper function hides these details from us, transparently calling
223 .BR rt_sigprocmask ()
224 when the kernel provides it.
226 .SH SEE ALSO
227 .BR kill (2),
228 .BR pause (2),
229 .BR sigaction (2),
230 .BR signal (2),
231 .BR sigpending (2),
232 .BR sigsuspend (2),
233 .BR pthread_sigmask (3),
234 .BR sigqueue (3),
235 .BR sigsetops (3),
236 .BR signal (7)