OSDN Git Service

f0ddc6cfc2cd86847698cf6202a9ce40de21e6bf
[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\-02\-04 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 POSIX.1\-2001.
71 .SH 注意
72 新しいスレッドは、スレッドを作成したスレッドのシグナルマスクのコピーを
73 継承する。
74 .SH 例
75 以下のプログラムは、メインスレッドでシグナルのいくつかを禁止 (block)
76 するように設定を行い、 \fBsigwait\fP(3) 経由でそれらのシグナルを集める
77 専用のスレッドを作成する。
78 下記のシェルのセッションはその利用例を示したものである。
79
80 .in +4n
81 .nf
82 $\fB ./a.out &\fP
83 [1] 5423
84 $\fB kill \-QUIT %1\fP
85 Signal handling thread got signal 3
86 $\fB kill \-USR1 %1\fP
87 Signal handling thread got signal 10
88 $\fB kill \-TERM %1\fP
89 [1]+  Terminated              ./a.out
90 .fi
91 .in
92 .SS プログラムのソース
93 \&
94 .nf
95 #include <pthread.h>
96 #include <stdio.h>
97 #include <stdlib.h>
98 #include <unistd.h>
99 #include <signal.h>
100 #include <errno.h>
101
102 /* Simple error handling functions */
103
104 #define handle_error_en(en, msg) \e
105         do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
106
107 static void *
108 sig_thread(void *arg)
109 {
110     sigset_t *set = arg;
111     int s, sig;
112
113     for (;;) {
114         s = sigwait(set, &sig);
115         if (s != 0)
116             handle_error_en(s, "sigwait");
117         printf("Signal handling thread got signal %d\en", sig);
118     }
119 }
120
121 int
122 main(int argc, char *argv[])
123 {
124     pthread_t thread;
125     sigset_t set;
126     int s;
127
128     /* Block SIGQUIT and SIGUSR1; other threads created by main()
129        will inherit a copy of the signal mask. */
130
131     sigemptyset(&set);
132     sigaddset(&set, SIGQUIT);
133     sigaddset(&set, SIGUSR1);
134     s = pthread_sigmask(SIG_BLOCK, &set, NULL);
135     if (s != 0)
136         handle_error_en(s, "pthread_sigmask");
137
138     s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);
139     if (s != 0)
140         handle_error_en(s, "pthread_create");
141
142     /* Main thread carries on to create other threads and/or do
143        other work */
144
145     pause();            /* Dummy pause so we can test program */
146 }
147 .fi
148 .SH 関連項目
149 \fBsigaction\fP(2), \fBsigpending\fP(2), \fBsigprocmask\fP(2), \fBpthread_create\fP(3),
150 \fBpthread_kill\fP(3), \fBsigsetops\fP(3), \fBpthreads\fP(7), \fBsignal\fP(7)
151 .SH この文書について
152 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部
153 である。プロジェクトの説明とバグ報告に関する情報は
154 http://www.kernel.org/doc/man\-pages/ に書かれている。