1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"*******************************************************************
28 .\" This file was generated with po4a. Translate the source file.
30 .\"*******************************************************************
32 .\" Japanese Version Copyright (c) 2012 Akihiro MOTOKI
33 .\" all rights reserved.
34 .\" Translated 2012-05-04, Akihiro MOTOKI <amotoki@gmail.com>
36 .TH PTHREAD_SIGMASK 3 2014\-05\-19 Linux "Linux Programmer's Manual"
38 pthread_sigmask \- 禁止するシグナルマスクの確認と変更を行う
41 \fB#include <signal.h>\fP
43 \fBint pthread_sigmask(int \fP\fIhow\fP\fB, const sigset_t *\fP\fIset\fP\fB, sigset_t *\fP\fIoldset\fP\fB);\fP
46 \fI\-pthread\fP を付けてコンパイルとリンクを行う。
49 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
53 \fBpthread_sigmask\fP():
55 _POSIX_C_SOURCE\ >=\ 199506L || _XOPEN_SOURCE\ >=\ 500
59 \fBpthread_sigmask\fP() 関数は \fBsigprocmask\fP(2) と全く同様だが、
60 マルチスレッドプログラムでの利用が POSIX.1\-2001 で明示的に規定されて
61 いる点が異なる。他の違いはこのマニュアルページで説明する。
63 この関数の引き数と動作の説明は \fBsigprocmask\fP(2) を参照。
65 成功すると、 \fBpthread_sigmask\fP() は 0 を返す。
68 \fBsigprocmask\fP(2) を参照。
70 .SS "マルチスレッディング (pthreads(7) 参照)"
71 \fBpthread_sigmask\fP() 関数はスレッドセーフである。
75 新しいスレッドは、スレッドを作成したスレッドのシグナルマスクのコピーを
78 以下のプログラムは、メインスレッドでシグナルのいくつかを禁止 (block)
79 するように設定を行い、 \fBsigwait\fP(3) 経由でそれらのシグナルを集める
81 下記のシェルのセッションはその利用例を示したものである。
87 $\fB kill \-QUIT %1\fP
88 Signal handling thread got signal 3
89 $\fB kill \-USR1 %1\fP
90 Signal handling thread got signal 10
91 $\fB kill \-TERM %1\fP
92 [1]+ Terminated ./a.out
105 /* Simple error handling functions */
107 #define handle_error_en(en, msg) \e
108 do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
111 sig_thread(void *arg)
117 s = sigwait(set, &sig);
119 handle_error_en(s, "sigwait");
120 printf("Signal handling thread got signal %d\en", sig);
125 main(int argc, char *argv[])
131 /* Block SIGQUIT and SIGUSR1; other threads created by main()
132 will inherit a copy of the signal mask. */
135 sigaddset(&set, SIGQUIT);
136 sigaddset(&set, SIGUSR1);
137 s = pthread_sigmask(SIG_BLOCK, &set, NULL);
139 handle_error_en(s, "pthread_sigmask");
141 s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
143 handle_error_en(s, "pthread_create");
145 /* Main thread carries on to create other threads and/or do
148 pause(); /* Dummy pause so we can test program */
152 \fBsigaction\fP(2), \fBsigpending\fP(2), \fBsigprocmask\fP(2), \fBpthread_create\fP(3),
153 \fBpthread_kill\fP(3), \fBsigsetops\fP(3), \fBpthreads\fP(7), \fBsignal\fP(7)
155 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
156 である。プロジェクトの説明とバグ報告に関する情報は
157 http://www.kernel.org/doc/man\-pages/ に書かれている。