OSDN Git Service

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