OSDN Git Service

5ba9733cb6e4fd760b7aa23506b9b35a81920095
[linuxjm/LDP_man-pages.git] / draft / 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 .TH PTHREAD_SIGMASK 3 2012\-08\-03 Linux "Linux Programmer's Manual"
32 .SH 名前
33 pthread_sigmask \- 禁止するシグナルマスクの確認と変更を行う
34 .SH 書式
35 .nf
36 \fB#include <signal.h>\fP
37
38 \fBint pthread_sigmask(int \fP\fIhow\fP\fB, const sigset_t *\fP\fIset\fP\fB, sigset_t *\fP\fIoldset\fP\fB);\fP
39 .fi
40 .sp
41 \fI\-pthread\fP を付けてコンパイルとリンクを行う。
42 .SH 説明
43 \fBpthread_sigmask\fP() 関数は \fBsigprocmask\fP(2) と全く同様だが、
44 マルチスレッドプログラムでの利用が POSIX.1\-2001 で明示的に規定されて
45 いる点が異なる。他の違いはこのマニュアルページで説明する。
46
47 この関数の引き数と動作の説明は \fBsigprocmask\fP(2) を参照。
48 .SH 返り値
49 成功すると、 \fBpthread_sigmask\fP() は 0 を返す。
50 エラーの場合、エラー番号を返す。
51 .SH エラー
52 \fBsigprocmask\fP(2) を参照。
53 .SH 準拠
54 POSIX.1\-2001.
55 .SH 注意
56 新しいスレッドは、スレッドを作成したスレッドのシグナルマスクのコピーを
57 継承する。
58 .SH 例
59 以下のプログラムは、メインスレッドでシグナルのいくつかを禁止 (block)
60 するように設定を行い、 \fBsigwait\fP(3) 経由でそれらのシグナルを集める
61 専用のスレッドを作成する。
62 下記のシェルのセッションはその利用例を示したものである。
63
64 .in +4n
65 .nf
66 $\fB ./a.out &\fP
67 [1] 5423
68 $\fB kill \-QUIT %1\fP
69 Signal handling thread got signal 3
70 $\fB kill \-USR1 %1\fP
71 Signal handling thread got signal 10
72 $\fB kill \-TERM %1\fP
73 [1]+  Terminated              ./a.out
74 .fi
75 .in
76 .SS プログラムのソース
77 \&
78 .nf
79 #include <pthread.h>
80 #include <stdio.h>
81 #include <stdlib.h>
82 #include <unistd.h>
83 #include <signal.h>
84 #include <errno.h>
85
86 /* Simple error handling functions */
87
88 #define handle_error_en(en, msg) \e
89         do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
90
91 static void *
92 sig_thread(void *arg)
93 {
94     sigset_t *set = arg;
95     int s, sig;
96
97     for (;;) {
98         s = sigwait(set, &sig);
99         if (s != 0)
100             handle_error_en(s, "sigwait");
101         printf("Signal handling thread got signal %d\en", sig);
102     }
103 }
104
105 int
106 main(int argc, char *argv[])
107 {
108     pthread_t thread;
109     sigset_t set;
110     int s;
111
112     /* Block SIGQUIT and SIGUSR1; other threads created by main()
113        will inherit a copy of the signal mask. */
114
115     sigemptyset(&set);
116     sigaddset(&set, SIGQUIT);
117     sigaddset(&set, SIGUSR1);
118     s = pthread_sigmask(SIG_BLOCK, &set, NULL);
119     if (s != 0)
120         handle_error_en(s, "pthread_sigmask");
121
122     s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
123     if (s != 0)
124         handle_error_en(s, "pthread_create");
125
126     /* Main thread carries on to create other threads and/or do
127        other work */
128
129     pause();            /* Dummy pause so we can test program */
130 }
131 .fi
132 .SH 関連項目
133 \fBsigaction\fP(2), \fBsigpending\fP(2), \fBsigprocmask\fP(2), \fBpthread_create\fP(3),
134 \fBpthread_kill\fP(3), \fBsigsetops\fP(3), \fBpthreads\fP(7), \fBsignal\fP(7)
135 .SH この文書について
136 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
137 である。プロジェクトの説明とバグ報告に関する情報は
138 http://www.kernel.org/doc/man\-pages/ に書かれている。