1 .\" Copyright (C) 1996-1999 Free Software Foundation, Inc.
3 .\" Permission is granted to make and distribute verbatim copies of
4 .\" this manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of
8 .\" this manual under the conditions for verbatim copying, provided that
9 .\" the entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Permission is granted to copy and distribute translations of this
13 .\" manual into another language, under the above conditions for modified
14 .\" versions, except that this permission notice may be stated in a
15 .\" translation approved by the Foundation.
17 .\" Copyright (C) 1996 Xavier Leroy.
19 .\" Japanese Version Copyright (C) 2002-2003 Suzuki Takashi
20 .\" all rights reserved.
21 .\" Translated Tue Dec 31 20:02:27 JST 2002
22 .\" by Suzuki Takashi.
24 .\"WORD: handling of signals ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥ê¥ó¥°
25 .\"WORD: signal mask ¥·¥°¥Ê¥ë¥Þ¥¹¥¯
26 .\"WORD: calling thread ¸Æ¤Ó½Ð¤·¥¹¥ì¥Ã¥É
27 .\"WORD: signal action ¥·¥°¥Ê¥ë¥¢¥¯¥·¥ç¥ó
28 .\"WORD: signal handler ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é
31 .TH PTHREAD_SIGNAL 3 LinuxThreads
35 .\"O pthread_sigmask, pthread_kill, sigwait \- handling of signals in threads
37 pthread_sigmask, pthread_kill, sigwait \- ¥¹¥ì¥Ã¥ÉÆâ¤Ç¤Î¥·¥°¥Ê¥ë¥Ï¥ó¥É¥ê¥ó¥°
41 .B #include <pthread.h>
43 .B #include <signal.h>
45 .BI "int pthread_sigmask(int " how ", const sigset_t *" newmask ", sigset_t *" oldmask ");"
47 .BI "int pthread_kill(pthread_t " thread ", int " signo ");"
49 .BI "int sigwait(const sigset_t *" set ", int *" sig ");"
54 .\"O .B "pthread_sigmask"
55 .\"O changes the signal mask for the calling thread as
64 .\"O the previous signal mask is stored in the location pointed to
68 ¤Ï¸Æ¤Ó½Ð¤·¥¹¥ì¥Ã¥É¤Î¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤ò
73 ¤Ç»ØÄꤵ¤ì¤ë¤è¤¦¤ËÊѹ¹¤¹¤ë¡£
77 ¤Ç¤Ê¤¤¤È¤¤Ë¤Ï¡¢Ä¾Á°¤Î¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤¬
79 ¤Ç»Ø¤·¼¨¤µ¤ì¤ëÎΰè¤Ë³ÊǼ¤µ¤ì¤ë¡£
81 .\"O The meaning of the
85 .\"O arguments is the same as for
86 .\"O .BR "sigprocmask" (2).
90 .\"O .BR "SIG_SETMASK" ,
91 .\"O the signal mask is set to
96 .\"O .BR "SIG_BLOCK" ,
97 .\"O the signals specified to
99 .\"O are added to the current signal mask. If
102 .\"O .BR "SIG_UNBLOCK" ,
104 .\"O signals specified to
106 .\"O are removed from the current signal
113 .BR "sigprocmask" (2)
114 ¤Î°ú¿ô¤Î°ÕÌ£¤ÈƱ¤¸¤Ç¤¢¤ë¡£
127 ¤Ç»ØÄꤵ¤ì¤ë¥·¥°¥Ê¥ë¤¬¸½»þÅÀ¤Î¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤ËÄɲ䵤ì¤ë¡£
133 ¤Ç»ØÄꤵ¤ì¤ë¥·¥°¥Ê¥ë¤¬¸½»þÅÀ¤Î¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤«¤é¼è¤ê½ü¤«¤ì¤ë¡£
135 .\"O Recall that signal masks are set on a per-thread basis, but signal
136 .\"O actions and signal handlers, as set with
137 .\"O .BR "sigaction" (2),
139 .\"O between all threads.
140 ¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤Ï¥¹¥ì¥Ã¥É¤´¤È¤ËÀßÄꤵ¤ì¤ë¤³¤È¤ò»×¤¤½Ð¤·¤Æ¤Û¤·¤¤¡£
144 ¥·¥°¥Ê¥ë¥¢¥¯¥·¥ç¥ó¤È¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ï¡¢
145 ¤¹¤Ù¤Æ¤Î¥¹¥ì¥Ã¥É¤Ç¶¦Ä̤Ǥ¢¤ë¡£
147 .\"O .B "pthread_kill"
148 .\"O send signal number
152 .\"O The signal is delivered and handled as described in
163 ¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¤è¤¦¤ËÇÛÁ÷¤µ¤ì¥Ï¥ó¥É¥ë¤µ¤ì¤ë¡£
166 .\"O suspends the calling thread until one of the signals
169 .\"O is delivered to the calling thread. It then stores the number
170 .\"O of the signal received in the location pointed to by
173 .\"O returns. The signals in
175 .\"O must be blocked and not ignored on
178 .\"O If the delivered signal has a signal handler
179 .\"O function attached, that function is
185 ¤Ç»ØÄꤵ¤ì¤ë¥·¥°¥Ê¥ë¤Î¤¦¤Á¤¤¤º¤ì¤« 1 ¤Ä¤¬¸Æ¤Ó½Ð¤·¥¹¥ì¥Ã¥É¤Ë
186 ÇÛÁ÷¤µ¤ì¤ë¤Þ¤Ç¸Æ¤Ó½Ð¤·¥¹¥ì¥Ã¥É¤Î¼Â¹Ô¤òÄä»ß¤¹¤ë¡£
187 ¤½¤·¤Æ¼õ¿®¤·¤¿¥·¥°¥Ê¥ë¤Î¿ô¤ò
189 ¤Ç»Ø¤·¼¨¤µ¤ì¤ëÎΰè¤Ë³ÊǼ¤·¤ÆÊ֤롣
191 ¤Ç»ØÄꤵ¤ì¤ë¥·¥°¥Ê¥ë¤Ï
193 ¤ËÆþ¤ë¤È¤¤Ë¥Ö¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢Ìµ»ë¤µ¤ì¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
194 ÇÛÁ÷¤µ¤ì¤¿¥·¥°¥Ê¥ë¤ËÂФ¹¤ë¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Æ¤â¡¢
195 ¥Ï¥ó¥É¥é´Ø¿ô¤Ï¸Æ¤Ó½Ð¤µ¤ì
199 .\"O .SH CANCELLATION
203 .\"O is a cancellation point.
205 ¤Ï¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ç¤¢¤ë¡£
207 .\"O .SH "RETURN VALUE"
210 .\"O On success, 0 is returned. On failure, a non-zero error code is returned.
211 À®¸ù¤¹¤ë¤È¡¢0 ¤¬Ê֤롣
212 ¼ºÇԤξì¹ç¡¢Èó 0 ¤Î¥¨¥é¡¼¥³¡¼¥É¤¬Ê֤롣
218 .\"O .B "pthread_sigmask"
219 .\"O function returns the following error codes
226 .\"O .BR "SIG_SETMASK" ,
227 .\"O .BR "SIG_BLOCK" ,
229 .\"O .B "SIG_UNBLOCK"
232 ¤Ï¥¨¥é¡¼¤Î¤È¤¡¢¼¡¤Î¤è¤¦¤Ê¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹:
250 .\"O point to invalid addresses
257 ¤¬Ìµ¸ú¤Ê¥¢¥É¥ì¥¹¤ò»Ø¤·¤Æ¤¤¤ë¡£
261 .\"O .B "pthread_kill"
262 .\"O function returns the following error codes
268 .\"O is not a valid signal number
271 ¤Ï¥¨¥é¡¼¤Î¤È¤¡¢¼¡¤Î¤è¤¦¤Ê¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹:
276 ¤Ï͸ú¤Ê¥·¥°¥Ê¥ëÈÖ¹æ¤Ç¤Ê¤¤¡£
282 .\"O does not exist (e.g. it has already terminated)
288 ¤Ï¸ºß¤·¤Ê¤¤ (Î㤨¤Ð¡¢¤½¤Î¥¹¥ì¥Ã¥É¤Ï¤¹¤Ç¤Ë½ªÎ»¤·¤Æ¤¤¤ë) ¡£
293 .\"O function never returns an error.
296 ¤¬¥¨¥é¡¼¤òÊÖ¤¹¤³¤È¤Ï¤Ê¤¤¡£
300 Xavier Leroy <Xavier.Leroy@inria.fr>
304 .BR "sigprocmask" (2),
307 .BR "sigsuspend" (2).
314 .\"O to work reliably, the signals being waited for must be
315 .\"O blocked in all threads, not only in the calling thread, since
316 .\"O otherwise the POSIX semantics for signal delivery do not guarantee
317 .\"O that it's the thread doing the
319 .\"O that will receive the signal.
320 .\"O The best way to achieve this is block those signals before any threads
321 .\"O are created, and never unblock them in the program other than by
325 ¤¬³Î¼Â¤Ëµ¡Ç½¤¹¤ë¤è¤¦¤Ë¡¢
326 ÇÛÁ÷¤òÂԤĥ·¥°¥Ê¥ë¤Ï¡¢¸Æ¤Ó½Ð¤·¥¹¥ì¥Ã¥É¤À¤±¤Ç¤Ê¤¯
327 ¤¹¤Ù¤Æ¤Î¥¹¥ì¥Ã¥É¤Ç¥Ö¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
328 ¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¡¢POSIX ¤Î¥·¥°¥Ê¥ëÇÛÁ÷µ¡¹½¤Ï
329 ¥·¥°¥Ê¥ë¤ò¼õ¿®¤¹¤ë¥¹¥ì¥Ã¥É¤¬
331 ¤ò¸Æ¤Ó½Ð¤·¤Æ¤¤¤ë¥¹¥ì¥Ã¥É¤È¤Ê¤ë¤³¤È¤òÊݾڤ·¤Ê¤¤¡£
332 ¤³¤ì¤ò¼Â¸½¤¹¤ëºÇ¤â¤è¤¤ÊýË¡¤Ï¡¢
333 ¤É¤Î¥¹¥ì¥Ã¥É¤òÀ¸À®¤¹¤ë¤è¤ê¤âÁ°¤Ë¤½¤ì¤é¤Î¥·¥°¥Ê¥ë¤ò¥Ö¥í¥Ã¥¯¤·¡¢
336 ¤ò¸Æ¤Ó½Ð¤¹°Ê³°¡¢¥Ö¥í¥Ã¥¯¤ò²ò½ü¤·¤Ê¤¤¤³¤È¤Ç¤¢¤ë¡£
341 .\"O Signal handling in LinuxThreads departs significantly from the POSIX
342 .\"O standard. According to the standard, ``asynchronous'' (external)
343 .\"O signals are addressed to the whole process (the collection of all
344 .\"O threads), which then delivers them to one particular thread. The
345 .\"O thread that actually receives the signal is any thread that does
346 .\"O not currently block the signal.
347 LinuxThreads ¤Î¥·¥°¥Ê¥ë¥Ï¥ó¥É¥ê¥ó¥°¤Ï POSIX ɸ½à¤È¤ÏÂ礤¯°Û¤Ê¤Ã¤Æ¤¤¤ë¡£
348 POSIX ɸ½à¤Ë¤è¤ë¤È¡¢¡ÖÈóƱ´ü¤Î¡× (³°Éô¤Î) ¥·¥°¥Ê¥ë¤Ï
349 ¥×¥í¥»¥¹Á´ÂÎ (¤¹¤Ù¤Æ¤Î¥¹¥ì¥Ã¥É¤Î½¸¤Þ¤ê) ¤ËÂФ·¤Æȯ¹Ô¤µ¤ì¡¢
350 ¤½¤Î¸åÆÃÄê¤Î 1 ¤Ä¤Î¥¹¥ì¥Ã¥É¤ËÇÛÁ÷¤µ¤ì¤ë¡£
351 ¼ÂºÝ¤Ë¥·¥°¥Ê¥ë¤ò¼õ¿®¤¹¤ë¥¹¥ì¥Ã¥É¤Ï
352 ¤½¤Î»þÅÀ¤Ç¥·¥°¥Ê¥ë¤ò¥Ö¥í¥Ã¥¯¤·¤Æ¤¤¤Ê¤¤¥¹¥ì¥Ã¥É¤Î¤¤¤º¤ì¤«¤È¤Ê¤ë¡£
354 .\"O In LinuxThreads, each thread is actually a kernel process with its own
355 .\"O PID, so external signals are always directed to one particular thread.
356 .\"O If, for instance, another thread is blocked in
359 .\"O signal, it will not be restarted.
361 ¤½¤ì¤¾¤ì¤Î¥¹¥ì¥Ã¥É¤¬¼ÂºÝ¤Ë¤Ï¸ÇͤΠPID ¤ò¤â¤Ä¥«¡¼¥Í¥ë¥×¥í¥»¥¹¤Ç¤¢¤ë¤¿¤á¡¢
362 ³°Éô¤Î¥·¥°¥Ê¥ë¤ÏÆÃÄê¤Î 1 ¤Ä¤Î¥¹¥ì¥Ã¥É¤ËľÀÜÇÛÁ÷¤µ¤ì¤ë¡£
363 Î㤨¤Ð¡¢¤â¤·Ê̤Υ¹¥ì¥Ã¥É¤¬
365 ¤ò»È¤Ã¤Æ¤½¤Î¥·¥°¥Ê¥ë¤ò¥Ö¥í¥Ã¥¯¤·¤Æ¤â¡¢
366 ¤½¤Î¥¹¥ì¥Ã¥É¤¬ºÆ³«¤µ¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£
368 .\"O The LinuxThreads implementation of
370 .\"O installs dummy signal
371 .\"O handlers for the signals in
373 .\"O for the duration of the wait. Since
374 .\"O signal handlers are shared between all threads, other threads must not
375 .\"O attach their own signal handlers to these signals, or alternatively
376 .\"O they should all block these signals (which is recommended anyway --
377 .\"O see the Notes section).
379 ¤Î LinuxThreads ¤Î¼ÂÁõ¤Ç¤Ï¡¢
383 ¤Ë´Þ¤Þ¤ì¤ë¥·¥°¥Ê¥ë¤ËÂбþ¤¹¤ë¥À¥ß¡¼¤Î¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤òÅÐÏ¿¤¹¤ë¡£
384 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ï¤¹¤Ù¤Æ¤Î¥¹¥ì¥Ã¥É¤Ç¶¦Ä̤Ǥ¢¤ë¤¿¤á¡¢
385 ¾¤Î¥¹¥ì¥Ã¥É¤Ï¤³¤ì¤é¤Î¥·¥°¥Ê¥ë¤ËÂФ·¤ÆÆȼ«¤Î¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤òÅÐÏ¿¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
386 ¤¢¤ë¤¤¤Ï¤½¤ÎÂå¤ï¤ê¤Ë¡¢¤¹¤Ù¤Æ¤Î¥¹¥ì¥Ã¥É¤¬
387 ¤³¤ì¤é¤Î¥·¥°¥Ê¥ë¤ò¥Ö¥í¥Ã¥¯¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤
388 (¤³¤Î¤³¤È¤Ï¤È¤Ë¤«¤¯¿ä¾©¤µ¤ì¤Æ¤¤¤ë -- Ãí°Õ¤Î¥»¥¯¥·¥ç¥ó¤ò»²¾È¤Î¤³¤È) ¡£