1 .\" Copyright (c) 2000 Andries Brouwer <aeb@cwi.nl>
2 .\" and Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
4 .\" and Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
5 .\" <mtk.manpages@gmail.com>
6 .\" based on work by Rik Faith <faith@cs.unc.edu>
7 .\" and Mike Battersby <mike@starbug.apana.org.au>.
9 .\" Permission is granted to make and distribute verbatim copies of this
10 .\" manual provided the copyright notice and this permission notice are
11 .\" preserved on all copies.
13 .\" Permission is granted to copy and distribute modified versions of this
14 .\" manual under the conditions for verbatim copying, provided that the
15 .\" entire resulting derived work is distributed under the terms of a
16 .\" permission notice identical to this one.
18 .\" Since the Linux kernel and libraries are constantly changing, this
19 .\" manual page may be incorrect or out-of-date. The author(s) assume no
20 .\" responsibility for errors or omissions, or for damages resulting from
21 .\" the use of the information contained herein. The author(s) may not
22 .\" have taken the same level of care in the production of this manual,
23 .\" which is licensed free of charge, as they might when working
26 .\" Formatted or processed versions of this manual, if unaccompanied by
27 .\" the source, must acknowledge the copyright and authors of this work.
29 .\" Modified 2004-11-19, mtk:
30 .\" added pointer to sigaction.2 for details of ignoring SIGCHLD
31 .\" 2007-06-03, mtk: strengthened portability warning, and rewrote
33 .\" 2008-07-11, mtk: rewrote and expanded portability discussion.
35 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
36 .\" all rights reserved.
37 .\" Translated 1997-03-03, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Modified 2000-09-24, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
39 .\" Updated & Modified 2002-01-14, Yuichi SATO <ysato@h4.dion.ne.jp>
40 .\" Updated & Modified 2004-01-17, Yuichi SATO <ysato444@yahoo.co.jp>
41 .\" Updated & Modified 2005-01-07, Yuichi SATO
42 .\" Updated 2007-06-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.50
43 .\" Updated 2007-06-13, Akihiro MOTOKI, LDP v2.55
44 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
46 .\"WORD: signal ¥·¥°¥Ê¥ë
47 .\"WORD: signal handler ¥·¥°¥Ê¥ë¡¦¥Ï¥ó¥É¥é
48 .\"WORD: library ¥é¥¤¥Ö¥é¥ê
49 .\"WORD: semantics Êý¼°
50 .\"WORD: prototype ·¿Àë¸À
51 .\"WORD: architecture ¥¢¡¼¥¥Æ¥¯¥Á¥ã¡¼
52 .\"WORD: endless loop ̵¸Â¥ë¡¼¥×
53 .\"WORD: feature test macro µ¡Ç½¸¡ºº¥Þ¥¯¥í
54 .\"WORD: disposition ½èÍýÊýË¡
56 .TH SIGNAL 2 2008-07-11 "Linux" "Linux Programmer's Manual"
59 .\"O signal \- ANSI C signal handling
60 signal \- ANSI C ¥·¥°¥Ê¥ëÁàºî
63 .B #include <signal.h>
65 .B typedef void (*sighandler_t)(int);
67 .\"O .BI "sighandler_t signal(int " signum ", sighandler_t " handler );
68 .BI "sighandler_t signal(int " signum ", sighandler_t " sighandler );
73 .\"O varies across UNIX versions,
74 .\"O and has also varied historically across different versions of Linux.
75 .\"O \fBAvoid its use\fP: use
76 .\"O .BR sigaction (2)
78 .\"O See \fIPortability\fP below.
80 ¤ÎÆ°ºî¤Ï UNIX ¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¤è¤ê°Û¤Ê¤ë¡£
81 ¤Þ¤¿¡¢Îò»ËŪ¤Ë¸«¤Æ Linux ¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¤è¤Ã¤Æ¤â°Û¤Ê¤Ã¤Æ¤¤¤ë¡£
82 \fB¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î»ÈÍѤÏÈò¤±¡¢\fP
86 ²¼µ¤Î¡Ö°Ü¿¢À¡×¤ò»²¾È¡£
89 .\"O sets the disposition of the signal
96 .\"O or the address of a programmer-defined function (a "signal handler").
107 ¥×¥í¥°¥é¥Þ¤¬ÄêµÁ¤·¤¿´Ø¿ô (¡Ö¥·¥°¥Ê¥ë¡¦¥Ï¥ó¥É¥é¡×) ¤Î¥¢¥É¥ì¥¹¤Î
112 .\"O is delivered to the process, then one of the following happens:
115 ¤¬¥×¥í¥»¥¹¤ËÇÛÁ÷¤µ¤ì¤ë¤È¡¢°Ê²¼¤Î¤¤¤º¤ì¤«¤¬È¯À¸¤¹¤ë¡£
118 .\"O If the disposition is set to
120 .\"O then the signal is ignored.
123 ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤½¤Î¥·¥°¥Ê¥ë¤Ï̵»ë¤µ¤ì¤ë¡£
126 .\"O If the disposition is set to
128 .\"O then the default action associated with the signal (see
133 ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¥·¥°¥Ê¥ë¤Ë´ØÏ¢¤Å¤±¤é¤ì¤¿
134 ¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤¬¹Ô¤ï¤ì¤ë
139 .\"O If the disposition is set to a function,
140 .\"O then first either the disposition is reset to
142 .\"O or the signal is blocked (see \fIPortability\fP below), and then
144 .\"O is called with argument
146 ½èÍýÊýË¡¤È¤·¤Æ´Ø¿ô¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
149 ¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë¤«¤½¤Î¥·¥°¥Ê¥ë¤Î¥Ö¥í¥Ã¥¯¤¬¼Â¹Ô¤µ¤ì¤¿¸å¡¢
154 .\"O If invocation of the handler caused the signal to be blocked,
155 .\"O then the signal is unblocked upon return from the handler.
156 ¥Ï¥ó¥É¥é¤¬µ¯Æ°¤µ¤ì¤ëºÝ¤Ë¥·¥°¥Ê¥ë¤¬¥Ö¥í¥Ã¥¯¤µ¤ì¤¿¾ì¹ç¡¢
157 ¥Ï¥ó¥É¥é¤¬ÊÖ¤ëºÝ¤Ë¤½¤Î¥·¥°¥Ê¥ë¤Î¥Ö¥í¥Ã¥¯¤¬²ò½ü¤µ¤ì¤ë¡£
163 .\"O cannot be caught or ignored.
168 ¤ÏÊ᪤Ǥ¤º¡¢Ìµ»ë¤¹¤ë¤³¤È¤â¤Ç¤¤Ê¤¤¡£
169 .\"O .SH "RETURN VALUE"
172 .\"O returns the previous value of the signal handler, or
176 ¤Ï¡¢º£¤Þ¤Ç¤Î¥·¥°¥Ê¥ë¡¦¥Ï¥ó¥É¥é¤ÎÃͤòÊÖ¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï
187 .\"O .SH "CONFORMING TO"
189 C89, C99, POSIX.1-2001.
194 .\"O in a multithreaded process are unspecified.
195 ¥Þ¥ë¥Á¥¹¥ì¥Ã¥É¥×¥í¥»¥¹¤Ë¤ª¤±¤ë
197 ¤Î·ë²Ì¤Ï¡¢»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
199 .\"O According to POSIX, the behavior of a process is undefined after it
205 .\"O signal that was not generated by
217 ¥·¥°¥Ê¥ë¤ò̵»ë¤·¤¿¸å¤ÎÆ°ºî¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£
218 .\"O Integer division by zero has undefined result.
219 .\"O On some architectures it will generate a
222 .\"O (Also dividing the most negative integer by \-1 may generate
224 .\"O Ignoring this signal might lead to an endless loop.
225 0 ¤Ë¤è¤ëÀ°¿ô³ä¤ê»»¤Î·ë²Ì¤Ï̤ÄêµÁ¤È¤Ê¤ë¡£
226 ¤¢¤ë¼ï¤Î¥¢¡¼¥¥Æ¥¯¥Á¥ã¤Ç¤Ï¡¢¤³¤ì¤Ï
229 (ƱÍͤËÉé¤ÎºÇÂçÀ°¿ô¤ò \-1 ¤Ç³ä¤ë¤È
231 ¤¬À¸À®¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£)
232 ¤³¤Î¥·¥°¥Ê¥ë¤ò̵»ë¤¹¤ë¤È̵¸Â¥ë¡¼¥×¤Ë´Ù¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
235 .\"O .BR sigaction (2)
236 .\"O for details on what happens when
243 ¤òÀßÄꤷ¤¿¾ì¹ç¤Î¾ÜºÙ¤ÊÆ°ºî¤Ë¤Ä¤¤¤Æ¤Ï¡¢
249 .\"O for a list of the async-signal-safe functions that can be
250 .\"O safely called from inside a signal handler.
251 ¥·¥°¥Ê¥ë¡¦¥Ï¥ó¥É¥éÆ⤫¤é°ÂÁ´¤Ë¸Æ¤Ó½Ð¤¹¤³¤È¤¬¤Ç¤¤ë¡¢
252 async-signal-safe functions (ÈóƱ´ü¥·¥ó¥°¥ë¤Ç°ÂÁ´¤Ê´Ø¿ô) ¤Î
259 .\"O is a GNU extension.
261 ¤Î»ÈÍÑ¤Ï GNU ³ÈÄ¥¤Ç¤¢¤ë¡£
262 .\"O Various versions of libc predefine this type; libc4 and libc5 define
263 .\"O .IR SignalHandler ;
268 .\"O is defined, also
269 .\"O .IR sighandler_t .
270 ³Æ¼ï¥Ð¡¼¥¸¥ç¥ó¤Î libc ¤Ç¤³¤Î·¿¤ÏÄêµÁºÑ¤ß¤Ç¤¢¤ë;
278 ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï
281 .\"O Without use of such a type, the declaration of
283 .\"O is the somewhat harder to read:
284 ¤³¤Î¤è¤¦¤Ê·¿¤ò»ÈÍѤ·¤Ê¤¤¤È¡¢
286 ¤ÎÀë¸À¤ÏÆɤߤˤ¯¤¤¤â¤Î¤È¤Ê¤ë¡£
290 .BI "void ( *" signal "(int " signum ", void (*" handler ")(int)) ) (int);"
295 .\"O The only portable use of
297 .\"O is to set a signal's disposition to
301 .\"O The semantics when using
303 .\"O to establish a signal handler vary across systems
304 .\"O (and POSIX.1 explicitly permits this variation);
305 .\"O .B do not use it for this purpose.
308 ¤Î»È¤¤Êý¤Ï¡¢¥·¥°¥Ê¥ë¤Î½èÍýÊýË¡¤ò
312 ¤ËÀßÄꤹ¤ëÊýË¡¤À¤±¤Ç¤¢¤ë¡£
313 ¥·¥°¥Ê¥ë¡¦¥Ï¥ó¥É¥é¤òÀßÄꤹ¤ë¤Î¤Ë
315 ¤ò»È¤Ã¤¿¤È¤¤ÎÆ°ºî¤Ï¥·¥¹¥Æ¥à¤Ë¤è¤ê°Û¤Ê¤ë
316 (POSIX.1 ¤ÏÌÀ¼¨Åª¤Ë¤³¤Î°ã¤¤¤òǧ¤á¤Æ¤¤¤ë)¡£
317 .B "°Ü¿¢À¤¬É¬ÍפʤȤ¤Ï¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»ÈÍѤ·¤Ê¤¤¤³¤È¡£"
319 .\"O POSIX.1 solved the portability mess by specifying
320 .\"O .BR sigaction (2),
321 .\"O which provides explicit control of the semantics when a
322 .\"O signal handler is invoked; use that interface instead of
326 ¤òµ¬Äꤹ¤ë¤³¤È¤Ç°Ü¿¢À¤Ë´Ø¤¹¤ëº®Íð¤ò²ò·è¤·¤¿¡£
328 ¤Ï¥·¥°¥Ê¥ë¡¦¥Ï¥ó¥É¥é¤¬µ¯Æ°¤µ¤ì¤ëºÝ¤ÎµóÆ°¤òÌÀ¼¨Åª¤ËÀ©¸æ¤Ç¤¤ë¡£
330 ¤ÎÂå¤ï¤ê¤Ë¤³¤Î¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤ò»È¤¦¤³¤È¡£
332 .\"O In the original UNIX systems, when a handler that was established using
334 .\"O was invoked by the delivery of a signal,
335 .\"O the disposition of the signal would be reset to
337 .\"O and the system did not block delivery of further instances of the signal.
338 .\"O System V also provides these semantics for
340 .\"O This was bad because the signal might be delivered again
341 .\"O before the handler had a chance to reestablish itself.
342 .\"O Furthermore, rapid deliveries of the same signal could
343 .\"O result in recursive invocations of the handler.
344 ¥ª¥ê¥¸¥Ê¥ë¤Î UNIX ¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
346 ¤ò»È¤Ã¤ÆÀßÄꤵ¤ì¤¿¥Ï¥ó¥É¥é¤¬¥·¥°¥Ê¥ë¤ÎÇÛÁ÷¤Ë¤è¤êµ¯Æ°¤µ¤ì¤ë¤È¡¢
347 ¤½¤Î¥·¥°¥Ê¥ë¤Î½èÍýÊýË¡¤Ï
349 ¤Ë¥ê¥»¥Ã¥È¤µ¤ì¡¢¥·¥¹¥Æ¥à¤ÏƱ¤¸¥·¥°¥Ê¥ë¤¬¤µ¤é¤ËÀ¸À®¤µ¤ì¤Æ¤â
350 ¥·¥°¥Ê¥ë¤ÎÇÛÁ÷¤ò¥Ö¥í¥Ã¥¯¤·¤Ê¤«¤Ã¤¿¡£
353 ¤ËÂФ·¤Æ¤³¤ì¤é¤ÎµóÆ°¤òµ¬Äꤷ¤Æ¤¤¤ë¡£
354 ¤³¤¦¤·¤¿µóÆ°¤Ï¤Þ¤º¤¯¡¢¥Ï¥ó¥É¥é¤¬¥Ï¥ó¥É¥é¼«¿È¤òºÆÀßÄꤹ¤ëµ¡²ñ¤¬
355 Íè¤ë¤è¤êÁ°¤Ë¡¢Æ±¤¸¥·¥°¥Ê¥ë¤¬¤Þ¤¿ÇÛÁ÷¤µ¤ì¤ë²ÄǽÀ¤¬¤¢¤ë¡£
356 ¤µ¤é¤Ë¡¢Æ±¤¸¥·¥°¥Ê¥ë¤¬Î©¤Æ³¤±¤ËÇÛÁ÷¤µ¤ì¤ë¤È¡¢Æ±¤¸¥·¥°¥Ê¥ë¤¬
357 ¥Ï¥ó¥É¥é¤ò·«¤êÊÖ¤·µ¯Æ°¤µ¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£
359 .\"O BSD improved on this situation by changing the semantics of
361 .\"O (but, unfortunately, silently changed the semantics
362 .\"O when establishing a handler with
364 .\"O On BSD, when a signal handler is invoked,
365 .\"O the signal disposition is not reset,
366 .\"O and further instances of the signal are blocked from
367 .\"O being delivered while the handler is executing.
368 BSD ¤Ç¤Ï¡¢¥·¥°¥Ê¥ë½èÍý¤ÎµóÆ°¤òÊѹ¹¤¹¤ë¤³¤È¤Ç¡¢¤³¤Î¾õ¶·¤ò²þÁ±¤·¤¿
369 (¤·¤«¤·¡¢»ÄÇ°¤Ê¤³¤È¤Ë¡¢
371 ¤ò»È¤Ã¤Æ¥Ï¥ó¥É¥é¤òÀßÄꤹ¤ëºÝ¤ËµóÆ°¤¬ÌۤäÆÊѹ¹¤µ¤ì¤ë)¡£
372 BSD ¤Ç¤Ï¡¢¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤¬µ¯Æ°¤µ¤ì¤¿ºÝ¡¢
373 ¥·¥°¥Ê¥ë¤Î½èÍýÊýË¡¤Ï¥ê¥»¥Ã¥È¤µ¤ì¤º¡¢
374 ¥Ï¥ó¥É¥é¤Î¼Â¹ÔÃæ¤Ï¡¢Æ±¤¸¥·¥°¥Ê¥ë¤Î¤µ¤é¤Ê¤ëÀ¸À®¤ÏÇÛÁ÷¤¬¥Ö¥í¥Ã¥¯¤µ¤ì¤ë¡£
376 .\"O The situation on Linux is as follows:
377 Linux ¤Ç¤Î¾õ¶·¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
381 .\"O system call provides System V semantics.
384 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï System V Êý¼°¤òÄ󶡤·¤Æ¤¤¤ë¡£
386 .\"O By default, in glibc 2 and later, the
388 .\"O wrapper function does not invoke the kernel system call.
389 .\"O Instead, it calls
390 .\"O .BR sigaction (2)
391 .\"O using flags that supply BSD semantics.
392 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢glibc 2 °Ê¹ß¤Ç¤Ï¡¢
394 ¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï¥«¡¼¥Í¥ë¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤òµ¯Æ°¤·¤Ê¤¤¡£
395 Âå¤ï¤ê¤Ë¡¢¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï BSD Êý¼°¤ò¼¨¤¹¥Õ¥é¥°¤ò»È¤Ã¤Æ
398 .\"O This default behavior is provided as long as the
400 .\"O feature test macro is defined.
404 .\"O it is also implicitly defined if one defines
405 .\"O .BR _GNU_SOURCE ,
406 .\"O and can of course be explicitly defined.
409 ¤òÄêµÁ¤·¤Æ¤¤¤ì¤Ð¡¢¤³¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤È¤Ê¤ë¡£
416 ¤¬ÄêµÁ¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï°ÅÌۤΤ¦¤Á¤ËÄêµÁ¤µ¤ì¡¢
417 ¤â¤Á¤í¤óÌÀ¼¨Åª¤ËÄêµÁ¤¹¤ë¤³¤È¤â¤Ç¤¤ë¡£
419 .\"O On glibc 2 and later, if the
421 .\"O feature test macro is not defined, then
423 .\"O provides System V semantics.
424 glibc 2 °Ê¹ß¤Ç¤Ï¡¢µ¡Ç½¸¡ºº¥Þ¥¯¥í
426 ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
428 ¤Ï System V Êý¼°¤È¤Ê¤ë¡£
429 .\"O (The default implicit definition of
431 .\"O is not provided if one invokes
433 .\"O in one of its standard modes
434 .\"O .RI ( -std=xxx " or " -ansi )
435 .\"O or defines various other feature test macros such as
436 .\"O .BR _POSIX_SOURCE ,
437 .\"O .BR _XOPEN_SOURCE ,
439 .\"O .BR _SVID_SOURCE ;
441 .\"O .BR feature_test_macros (7).)
444 .RI ( -std=xxx " or " -ansi )
445 ¤Çµ¯Æ°¤µ¤ì¤¿¾ì¹ç¡¢¤â¤·¤¯¤Ï
449 ¤È¤¤¤Ã¤¿Â¾¤ÎÍÍ¡¹¤Êµ¡Ç½¸¡ºº¥Þ¥¯¥í¤¬ÄêµÁ¤µ¤ì¤¿¾ì¹ç¡¢
452 ¤Î°ÅÌÛ¤ÎÄêµÁ¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£
453 .BR feature_test_macros (7)
456 .\" System V semantics are also provided if one uses the separate
457 .\" .BR sysv_signal (3)
462 .\"O function in Linux libc4 and libc5 provide System V semantics.
463 .\"O If one on a libc5 system includes
464 .\"O .I <bsd/signal.h>
466 .\"O .IR <signal.h> ,
469 .\"O provides BSD semantics.
470 Linux ¤Î libc4 ¤È libc5 ¤Î
472 ´Ø¿ô¤Ï System V Êý¼°¤Ç¤¢¤ë¡£
473 libc5 ¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ
477 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤È¡¢
499 .BR siginterrupt (3),
503 .BR feature_test_macros (7),