1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH PTHREAD_SIGMASK 3 2011-10-16 "Linux" "Linux Programmer's Manual"
26 pthread_sigmask \- examine and change mask of blocked signals
29 .B #include <signal.h>
31 .BI "int pthread_sigmask(int " how ", const sigset_t *" set \
32 ", sigset_t *" oldset );
35 Compile and link with \fI\-pthread\fP.
38 .BR pthread_sigmask ()
41 with the difference that its use in multithreaded programs
42 is explicitly specified by POSIX.1-2001.
43 Other differences are noted in this page.
45 For a description of the arguments and operation of this function, see
49 .BR pthread_sigmask ()
51 on error, it returns an error number.
58 A new thread inherits a copy of its creator's signal mask.
60 The program below blocks some signals in the main thread,
61 and then creates a dedicated thread to fetch those signals via
63 The following shell session demonstrates its use:
69 .RB "$" " kill \-QUIT %1"
70 Signal handling thread got signal 3
71 .RB "$" " kill \-USR1 %1"
72 Signal handling thread got signal 10
73 .RB "$" " kill \-TERM %1"
74 [1]+ Terminated ./a.out
87 /* Simple error handling functions */
89 #define handle_error_en(en, msg) \\
90 do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
95 sigset_t *set = (sigset_t *) arg;
99 s = sigwait(set, &sig);
101 handle_error_en(s, "sigwait");
102 printf("Signal handling thread got signal %d\\n", sig);
107 main(int argc, char *argv[])
113 /* Block SIGQUIT and SIGUSR1; other threads created by main()
114 will inherit a copy of the signal mask. */
117 sigaddset(&set, SIGQUIT);
118 sigaddset(&set, SIGUSR1);
119 s = pthread_sigmask(SIG_BLOCK, &set, NULL);
121 handle_error_en(s, "pthread_sigmask");
123 s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
125 handle_error_en(s, "pthread_create");
127 /* Main thread carries on to create other threads and/or do
130 pause(); /* Dummy pause so we can test program */
137 .BR pthread_create (3),
138 .BR pthread_kill (3),