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