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
47 .\"WORD: signal handler シグナル・ハンドラ
48 .\"WORD: library ライブラリ
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
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 に設定されている場合、シグナルに関連づけられた
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
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.
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.
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 による整数割り算の結果は未定義となる。
232 このシグナルを無視すると無限ループに陥るかもしれない。
235 .\"O .BR sigaction (2)
236 .\"O for details on what happens when
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.
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 でこの型は定義済みである;
281 .\"O Without use of such a type, the declaration of
283 .\"O is the somewhat harder to read:
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.
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.
346 を使って設定されたハンドラがシグナルの配送により起動されると、
349 にリセットされ、システムは同じシグナルがさらに生成されても
354 こうした挙動はまずく、ハンドラがハンドラ自身を再設定する機会が
355 来るより前に、同じシグナルがまた配送される可能性がある。
356 さらに、同じシグナルが立て続けに配送されると、同じシグナルが
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 では、シグナル処理の挙動を変更することで、この状況を改善した
371 を使ってハンドラを設定する際に挙動が黙って変更される)。
372 BSD では、シグナルハンドラが起動された際、
374 ハンドラの実行中は、同じシグナルのさらなる生成は配送がブロックされる。
376 .\"O The situation on Linux is as follows:
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 が定義された場合には暗黙のうちに定義され、
419 .\"O On glibc 2 and later, if the
421 .\"O feature test macro is not defined, then
423 .\"O provides System V semantics.
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 )
449 といった他の様々な機能検査マクロが定義された場合、
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 の
498 .BR siginterrupt (3),