pthread_sigmask(3)
โจ NAME โจ
pthread_sigmask โ the glow-up version of blocking signals: examine and change your mask of blocked signals ๐
Feels like a libpthread (POSIX threads library) moment, ngl โ link it with -lpthread. ๐งต
โจ SYNOPSIS โจ
#include <signal.h>
int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);
๐ Feature Test Macro Requirements for glibc
(go check feature_test_macros(7) bestie, it's all there)
pthread_sigmask():
_POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500
๐ DESCRIPTION ๐
okay so pthread_sigmask() is literally just like sigprocmask(2), except โ and this is the part that eats โ its use in multithreaded programs is explicitly specified by POSIX.1. That's the whole plot twist. The other differences are noted further down this page, so don't skip them. ๐
For the full tea on the arguments and how this function actually operates, go read sigprocmask(2). No cap, everything's there.
๐ธ RETURN VALUE ๐ธ
Success? She returns 0. Error? She returns an error number. That's it, that's the vibe. โจ
๐ฆ ERRORS ๐ฆ
See sigprocmask(2). Yeah bestie, we're pointing you there again โ it's giving "read the other page." ๐
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
- Interface:
pthread_sigmask() - Attribute: Thread safety
- Value: MT-Safe ๐ฅ
๐ STANDARDS ๐
POSIX.1-2008. Periodt.
โญ HISTORY โญ
POSIX.1-2001. She's been iconic for a minute. ๐
๐ NOTES ๐
A new thread inherits a copy of its creator's signal mask. Genetics, but make it signals. ๐งฌ
The glibc pthread_sigmask() function silently ignores attempts to block the two real-time signals that are used internally by the NPTL threading implementation. Silently!! She just pretends she didn't hear you. ๐ See nptl(7) for the details.
๐ง EXAMPLES ๐ง
The program below blocks some signals in the main thread, and then creates a dedicated thread to fetch those signals via sigwait(3). Here's a shell session showing it in action, live and in 4K:
$ ./a.out &
[1] 5423
$ kill -QUIT %1
Signal handling thread got signal 3
$ kill -USR1 %1
Signal handling thread got signal 10
$ kill -TERM %1
[1]+ Terminated ./a.out
๐ธ Program source ๐ธ
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/* Simple error handling functions */
static void *
sig_thread(void *arg)
{
sigset_t *set = arg;
int s, sig;
for (;;) {
s = sigwait(set, &sig);
if (s != 0)
errc(EXIT_FAILURE, s, "sigwait");
printf("Signal handling thread got signal %d\n", sig);
}
}
int
main(void)
{
pthread_t thread;
sigset_t set;
int s;
/* Block SIGQUIT and SIGUSR1; other threads created by main()
will inherit a copy of the signal mask. */
sigemptyset(&set);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGUSR1);
s = pthread_sigmask(SIG_BLOCK, &set, NULL);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_sigmask");
s = pthread_create(&thread, NULL, &sig_thread, &set);
if (s != 0)
errc(EXIT_FAILURE, s, "pthread_create");
/* Main thread carries on to create other threads and/or do
other work. */
pause(); /* Dummy pause so we can test program */
}
๐ SEE ALSO ๐
sigaction(2), sigpending(2), sigprocmask(2), pthread_attr_setsigmask_np(3), pthread_create(3), pthread_kill(3), sigsetops(3), pthreads(7), signal(7)
okay that's the whole page, you ate that ๐
this was Linux man-pages 6.20, dated 2025-09-21 โ yes, pthread_sigmask(3) said it, bestie. go forth and mask responsibly ๐ซถ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms