OSDN Git Service

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