summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2013/man3p/pthread_sigmask.3p
blob: 7c70fb4caeef95d30687e1be96762816387aaac4 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
'\" et
.TH PTHREAD_SIGMASK "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.

.SH NAME
pthread_sigmask,
sigprocmask
\(em examine and change blocked signals
.SH SYNOPSIS
.LP
.nf
#include <signal.h>
.P
int pthread_sigmask(int \fIhow\fP, const sigset_t *restrict \fIset\fP,
    sigset_t *restrict \fIoset\fP);
int sigprocmask(int \fIhow\fP, const sigset_t *restrict \fIset\fP,
    sigset_t *restrict \fIoset\fP);
.fi
.SH DESCRIPTION
The
\fIpthread_sigmask\fR()
function shall examine or change (or both) the calling thread's
signal mask, regardless of the number of threads in the process. The
function shall be equivalent to
\fIsigprocmask\fR(),
without the restriction that the call be made in a single-threaded
process.
.P
In a single-threaded process, the
\fIsigprocmask\fR()
function shall examine or change (or both) the signal mask of the
calling thread.
.P
If the argument
.IR set
is not a null pointer, it points to a set of signals to be used to
change the currently blocked set.
.P
The argument
.IR how
indicates the way in which the set is changed, and the application
shall ensure it consists of one of the following values:
.IP SIG_BLOCK 12
The resulting set shall be the union of the current set and the signal
set pointed to by
.IR set .
.IP SIG_SETMASK 12
The resulting set shall be the signal set pointed to by
.IR set .
.IP SIG_UNBLOCK 12
The resulting set shall be the intersection of the current set and the
complement of the signal set pointed to by
.IR set .
.P
If the argument
.IR oset
is not a null pointer, the previous mask shall be stored in the location
pointed to by
.IR oset .
If
.IR set
is a null pointer, the value of the argument
.IR how
is not significant and the thread's signal mask shall be unchanged;
thus the call can be used to enquire about currently blocked signals.
.P
If there are any pending unblocked signals after the call to
\fIsigprocmask\fR(),
at least one of those signals shall be delivered before the call to
\fIsigprocmask\fR()
returns.
.P
It is not possible to block those signals which cannot be ignored.
This shall be enforced by the system without causing an error to be
indicated.
.P
If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS
signals are generated while they are blocked, the result is undefined,
unless the signal was generated by the action of another process, or by
one of the functions
\fIkill\fR(),
\fIpthread_kill\fR(),
\fIraise\fR(),
or
\fIsigqueue\fR().
.P
If
\fIsigprocmask\fR()
fails, the thread's signal mask shall not be changed.
.P
The use of the
\fIsigprocmask\fR()
function is unspecified in a multi-threaded process.
.SH "RETURN VALUE"
Upon successful completion
\fIpthread_sigmask\fR()
shall return 0; otherwise, it shall return the corresponding error
number.
.P
Upon successful completion,
\fIsigprocmask\fR()
shall return 0; otherwise, \(mi1 shall be returned,
.IR errno
shall be set to indicate the error, and the signal mask of the process
shall be unchanged.
.SH ERRORS
The
\fIpthread_sigmask\fR()
and
\fIsigprocmask\fR()
functions shall fail if:
.TP
.BR EINVAL
The value of the
.IR how
argument is not equal to one of the defined values.
.P
The
\fIpthread_sigmask\fR()
function shall not return an error code of
.BR [EINTR] .
.LP
.IR "The following sections are informative."
.SH EXAMPLES
.SS "Signaling in a Multi-Threaded Process"
.P
This example shows the use of
\fIpthread_sigmask\fR()
in order to deal with signals in a multi-threaded process. It provides
a fairly general framework that could be easily adapted/extended.
.sp
.RS 4
.nf
\fB
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
\&...
.P
static sigset_t   signal_mask;  /* signals to block         */
.P
int main (int argc, char *argv[])
{
    pthread_t  sig_thr_id;      /* signal handler thread ID */
    int        rc;              /* return code              */
.P
    sigemptyset (&signal_mask);
    sigaddset (&signal_mask, SIGINT);
    sigaddset (&signal_mask, SIGTERM);
    rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
    if (rc != 0) {
        /* handle error */
        ...
    }
    /* any newly created threads inherit the signal mask */
.P
    rc = pthread_create (&sig_thr_id, NULL, signal_thread, NULL);
    if (rc != 0) {
        /* handle error */
        ...
    }
.P
    /* APPLICATION CODE */
    ...
}
.P
void *signal_thread (void *arg)
{
    int       sig_caught;    /* signal caught       */
    int       rc;            /* returned code       */
.P
    rc = sigwait (&signal_mask, &sig_caught);
    if (rc != 0) {
        /* handle error */
    }
    switch (sig_caught)
    {
    case SIGINT:     /* process SIGINT  */
        ...
        break;
    case SIGTERM:    /* process SIGTERM */
        ...
        break;
    default:         /* should normally not happen */
        fprintf (stderr, "\enUnexpected signal %d\en", sig_caught);
        break;
    }
}
.fi \fR
.P
.RE
.SH "APPLICATION USAGE"
None.
.SH RATIONALE
When a thread's signal mask is changed in a signal-catching function
that is installed by
\fIsigaction\fR(),
the restoration of the signal mask on return from the signal-catching
function overrides that change (see
\fIsigaction\fR()).
If the signal-catching function was installed with
\fIsignal\fR(),
it is unspecified whether this occurs.
.P
See
\fIkill\fR()
for a discussion of the requirement on delivery of signals.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIexec\fR\^",
.IR "\fIkill\fR\^(\|)",
.IR "\fIsigaction\fR\^(\|)",
.IR "\fIsigaddset\fR\^(\|)",
.IR "\fIsigdelset\fR\^(\|)",
.IR "\fIsigemptyset\fR\^(\|)",
.IR "\fIsigfillset\fR\^(\|)",
.IR "\fIsigismember\fR\^(\|)",
.IR "\fIsigpending\fR\^(\|)",
.IR "\fIsigqueue\fR\^(\|)",
.IR "\fIsigsuspend\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2008,
.IR "\fB<signal.h>\fP"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.unix.org/online.html .

Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .