1PTHREAD_SIGMASK(3P)        POSIX Programmer's Manual       PTHREAD_SIGMASK(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       pthread_sigmask, sigprocmask — examine and change blocked signals
14

SYNOPSIS

16       #include <signal.h>
17
18       int pthread_sigmask(int how, const sigset_t *restrict set,
19           sigset_t *restrict oset);
20       int sigprocmask(int how, const sigset_t *restrict set,
21           sigset_t *restrict oset);
22

DESCRIPTION

24       The pthread_sigmask() function shall examine or change  (or  both)  the
25       calling  thread's  signal  mask, regardless of the number of threads in
26       the process. The function shall be equivalent to sigprocmask(), without
27       the restriction that the call be made in a single-threaded process.
28
29       In  a single-threaded process, the sigprocmask() function shall examine
30       or change (or both) the signal mask of the calling thread.
31
32       If the argument set is not a null pointer, it points to a set  of  sig‐
33       nals to be used to change the currently blocked set.
34
35       The argument how indicates the way in which the set is changed, and the
36       application shall ensure it consists of one of the following values:
37
38       SIG_BLOCK   The resulting set shall be the union of the current set and
39                   the signal set pointed to by set.
40
41       SIG_SETMASK The  resulting  set  shall  be the signal set pointed to by
42                   set.
43
44       SIG_UNBLOCK The resulting set shall be the intersection of the  current
45                   set and the complement of the signal set pointed to by set.
46
47       If  the argument oset is not a null pointer, the previous mask shall be
48       stored in the location pointed to by oset.  If set is a  null  pointer,
49       the  value of the argument how is not significant and the thread's sig‐
50       nal mask shall be unchanged; thus the call can be used to enquire about
51       currently blocked signals.
52
53       If  there  are any pending unblocked signals after the call to sigproc‐
54       mask(), at least one of those signals shall  be  delivered  before  the
55       call to sigprocmask() returns.
56
57       It  is  not  possible  to  block those signals which cannot be ignored.
58       This shall be enforced by the system without causing  an  error  to  be
59       indicated.
60
61       If  any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated
62       while they are blocked, the result is undefined, unless the signal  was
63       generated  by the action of another process, or by one of the functions
64       kill(), pthread_kill(), raise(), or sigqueue().
65
66       If sigprocmask() fails, the thread's signal mask shall not be changed.
67
68       The use of the  sigprocmask()  function  is  unspecified  in  a  multi-
69       threaded process.
70

RETURN VALUE

72       Upon successful completion pthread_sigmask() shall return 0; otherwise,
73       it shall return the corresponding error number.
74
75       Upon successful completion, sigprocmask() shall return 0; otherwise, −1
76       shall  be  returned,  errno shall be set to indicate the error, and the
77       signal mask of the process shall be unchanged.
78

ERRORS

80       The pthread_sigmask() and sigprocmask() functions shall fail if:
81
82       EINVAL The value of the how argument is not equal to one of the defined
83              values.
84
85       The  pthread_sigmask()  function  shall  not  return  an  error code of
86       [EINTR].
87
88       The following sections are informative.
89

EXAMPLES

91   Signaling in a Multi-Threaded Process
92       This example shows the use of pthread_sigmask() in order to  deal  with
93       signals  in  a  multi-threaded  process.  It  provides a fairly general
94       framework that could be easily adapted/extended.
95
96           #include <stdio.h>
97           #include <stdlib.h>
98           #include <pthread.h>
99           #include <signal.h>
100           #include <string.h>
101           #include <errno.h>
102           ...
103
104           static sigset_t   signal_mask;  /* signals to block         */
105
106           int main (int argc, char *argv[])
107           {
108               pthread_t  sig_thr_id;      /* signal handler thread ID */
109               int        rc;              /* return code              */
110
111               sigemptyset (&signal_mask);
112               sigaddset (&signal_mask, SIGINT);
113               sigaddset (&signal_mask, SIGTERM);
114               rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
115               if (rc != 0) {
116                   /* handle error */
117                   ...
118               }
119               /* any newly created threads inherit the signal mask */
120
121               rc = pthread_create (&sig_thr_id, NULL, signal_thread, NULL);
122               if (rc != 0) {
123                   /* handle error */
124                   ...
125               }
126
127               /* APPLICATION CODE */
128               ...
129           }
130
131           void *signal_thread (void *arg)
132           {
133               int       sig_caught;    /* signal caught       */
134               int       rc;            /* returned code       */
135
136               rc = sigwait (&signal_mask, &sig_caught);
137               if (rc != 0) {
138                   /* handle error */
139               }
140               switch (sig_caught)
141               {
142               case SIGINT:     /* process SIGINT  */
143                   ...
144                   break;
145               case SIGTERM:    /* process SIGTERM */
146                   ...
147                   break;
148               default:         /* should normally not happen */
149                   fprintf (stderr, "\nUnexpected signal %d\n", sig_caught);
150                   break;
151               }
152           }
153

APPLICATION USAGE

155       None.
156

RATIONALE

158       When a thread's signal mask is changed in  a  signal-catching  function
159       that is installed by sigaction(), the restoration of the signal mask on
160       return from the signal-catching function  overrides  that  change  (see
161       sigaction()).   If the signal-catching function was installed with sig‐
162       nal(), it is unspecified whether this occurs.
163
164       See kill() for a discussion of the requirement on delivery of signals.
165

FUTURE DIRECTIONS

167       None.
168

SEE ALSO

170       exec, kill(),  sigaction(),  sigaddset(),  sigdelset(),  sigemptyset(),
171       sigfillset(), sigismember(), sigpending(), sigqueue(), sigsuspend()
172
173       The Base Definitions volume of POSIX.1‐2008, <signal.h>
174
176       Portions  of  this text are reprinted and reproduced in electronic form
177       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
178       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
179       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
180       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
181       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
182       event of any discrepancy between this version and the original IEEE and
183       The Open Group Standard, the original IEEE and The Open Group  Standard
184       is  the  referee document. The original Standard can be obtained online
185       at http://www.unix.org/online.html .
186
187       Any typographical or formatting errors that appear  in  this  page  are
188       most likely to have been introduced during the conversion of the source
189       files to man page format. To report such errors,  see  https://www.ker
190       nel.org/doc/man-pages/reporting_bugs.html .
191
192
193
194IEEE/The Open Group                  2013                  PTHREAD_SIGMASK(3P)
Impressum