1PTHREAD_SIGMASK(3)         Linux Programmer's Manual        PTHREAD_SIGMASK(3)
2
3
4

NAME

6       pthread_sigmask - examine and change mask of blocked signals
7

SYNOPSIS

9       #include <signal.h>
10
11       int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);
12
13       Compile and link with -pthread.
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       pthread_sigmask():
18           _POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500
19

DESCRIPTION

21       The  pthread_sigmask()  function  is just like sigprocmask(2), with the
22       difference that its use in multithreaded programs is explicitly  speci‐
23       fied by POSIX.1.  Other differences are noted in this page.
24
25       For  a description of the arguments and operation of this function, see
26       sigprocmask(2).
27

RETURN VALUE

29       On success, pthread_sigmask() returns 0; on error, it returns an  error
30       number.
31

ERRORS

33       See sigprocmask(2).
34

ATTRIBUTES

36       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
37       tributes(7).
38
39       ┌────────────────────────────────────────────┬───────────────┬─────────┐
40Interface                                   Attribute     Value   
41       ├────────────────────────────────────────────┼───────────────┼─────────┤
42pthread_sigmask()                           │ Thread safety │ MT-Safe │
43       └────────────────────────────────────────────┴───────────────┴─────────┘
44

CONFORMING TO

46       POSIX.1-2001, POSIX.1-2008.
47

NOTES

49       A new thread inherits a copy of its creator's signal mask.
50
51       The glibc pthread_sigmask() function silently ignores attempts to block
52       the  two real-time signals that are used internally by the NPTL thread‐
53       ing implementation.  See nptl(7) for details.
54

EXAMPLES

56       The program below blocks some signals in the main thread, and then cre‐
57       ates  a  dedicated  thread  to fetch those signals via sigwait(3).  The
58       following shell session demonstrates its use:
59
60           $ ./a.out &
61           [1] 5423
62           $ kill -QUIT %1
63           Signal handling thread got signal 3
64           $ kill -USR1 %1
65           Signal handling thread got signal 10
66           $ kill -TERM %1
67           [1]+  Terminated              ./a.out
68
69   Program source
70
71       #include <pthread.h>
72       #include <stdio.h>
73       #include <stdlib.h>
74       #include <unistd.h>
75       #include <signal.h>
76       #include <errno.h>
77
78       /* Simple error handling functions */
79
80       #define handle_error_en(en, msg) \
81               do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
82
83       static void *
84       sig_thread(void *arg)
85       {
86           sigset_t *set = arg;