OSDN Git Service

Update release for LDP 3.67
[linuxjm/LDP_man-pages.git] / release / man3 / pthread_sigmask.3
1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" Japanese Version Copyright (c) 2012  Akihiro MOTOKI
33 .\"         all rights reserved.
34 .\" Translated 2012-05-04, Akihiro MOTOKI <amotoki@gmail.com>
35 .\"
36 .TH PTHREAD_SIGMASK 3 2014\-05\-19 Linux "Linux Programmer's Manual"
37 .SH 名前
38 pthread_sigmask \- 禁止するシグナルマスクの確認と変更を行う
39 .SH 書式
40 .nf
41 \fB#include <signal.h>\fP
42
43 \fBint pthread_sigmask(int \fP\fIhow\fP\fB, const sigset_t *\fP\fIset\fP\fB, sigset_t *\fP\fIoldset\fP\fB);\fP
44 .fi
45 .sp
46 \fI\-pthread\fP を付けてコンパイルとリンクを行う。
47 .sp
48 .in -4n
49 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
50 .in
51 .sp
52 .ad l
53 \fBpthread_sigmask\fP():
54 .RS 4
55 _POSIX_C_SOURCE\ >=\ 199506L || _XOPEN_SOURCE\ >=\ 500
56 .RE
57 .ad b
58 .SH 説明
59 \fBpthread_sigmask\fP() 関数は \fBsigprocmask\fP(2) と全く同様だが、
60 マルチスレッドプログラムでの利用が POSIX.1\-2001 で明示的に規定されて
61 いる点が異なる。他の違いはこのマニュアルページで説明する。
62
63 この関数の引き数と動作の説明は \fBsigprocmask\fP(2) を参照。
64 .SH 返り値
65 成功すると、 \fBpthread_sigmask\fP() は 0 を返す。
66 エラーの場合、エラー番号を返す。
67 .SH エラー
68 \fBsigprocmask\fP(2) を参照。
69 .SH 属性
70 .SS "マルチスレッディング (pthreads(7) 参照)"
71 \fBpthread_sigmask\fP() 関数はスレッドセーフである。
72 .SH 準拠
73 POSIX.1\-2001.
74 .SH 注意
75 新しいスレッドは、スレッドを作成したスレッドのシグナルマスクのコピーを
76 継承する。
77 .SH 例
78 以下のプログラムは、メインスレッドでシグナルのいくつかを禁止 (block)
79 するように設定を行い、 \fBsigwait\fP(3) 経由でそれらのシグナルを集める
80 専用のスレッドを作成する。
81 下記のシェルのセッションはその利用例を示したものである。
82
83 .in +4n
84 .nf
85 $\fB ./a.out &\fP
86 [1] 5423
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
93 .fi
94 .in
95 .SS プログラムのソース
96 \&
97 .nf
98 #include <pthread.h>
99 #include <stdio.h>
100 #include <stdlib.h>
101 #include <unistd.h>
102 #include <signal.h>
103 #include <errno.h>
104
105 /* Simple error handling functions */
106
107 #define handle_error_en(en, msg) \e
108         do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
109
110 static void *
111 sig_thread(void *arg)
112 {
113     sigset_t *set = arg;
114     int s, sig;
115
116     for (;;) {
117         s = sigwait(set, &sig);
118         if (s != 0)
119             handle_error_en(s, "sigwait");
120         printf("Signal handling thread got signal %d\en", sig);
121     }
122 }
123
124 int
125 main(int argc, char *argv[])
126 {
127     pthread_t thread;
128     sigset_t set;
129     int s;
130
131     /* Block SIGQUIT and SIGUSR1; other threads created by main()
132        will inherit a copy of the signal mask. */
133
134     sigemptyset(&set);
135     sigaddset(&set, SIGQUIT);
136     sigaddset(&set, SIGUSR1);
137     s = pthread_sigmask(SIG_BLOCK, &set, NULL);
138     if (s != 0)
139         handle_error_en(s, "pthread_sigmask");
140
141     s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
142     if (s != 0)
143         handle_error_en(s, "pthread_create");
144
145     /* Main thread carries on to create other threads and/or do
146        other work */
147
148     pause();            /* Dummy pause so we can test program */
149 }
150 .fi
151 .SH 関連項目
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)
154 .SH この文書について
155 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
156 である。プロジェクトの説明とバグ報告に関する情報は
157 http://www.kernel.org/doc/man\-pages/ に書かれている。