OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man2 / signal.2
1 .\" Copyright (c) 2000 Andries Brouwer <aeb@cwi.nl>
2 .\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" and Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
4 .\"      <mtk.manpages@gmail.com>
5 .\" based on work by Rik Faith <faith@cs.unc.edu>
6 .\" and Mike Battersby <mike@starbug.apana.org.au>.
7 .\"
8 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
17 .\"
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
24 .\" professionally.
25 .\"
26 .\" Formatted or processed versions of this manual, if unaccompanied by
27 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" %%%LICENSE_END
29 .\"
30 .\" Modified 2004-11-19, mtk:
31 .\" added pointer to sigaction.2 for details of ignoring SIGCHLD
32 .\" 2007-06-03, mtk: strengthened portability warning, and rewrote
33 .\"     various sections.
34 .\" 2008-07-11, mtk: rewrote and expanded portability discussion.
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" This file was generated with po4a. Translate the source file.
39 .\"
40 .\"*******************************************************************
41 .TH SIGNAL 2 2013\-02\-09 Linux "Linux Programmer's Manual"
42 .SH 名前
43 signal \- ANSI C シグナル操作
44 .SH 書式
45 \fB#include <signal.h>\fP
46 .sp
47 \fBtypedef void (*sighandler_t)(int);\fP
48 .sp
49 \fBsighandler_t signal(int \fP\fIsignum\fP\fB, sighandler_t \fP\fIsighandler\fP\fB);\fP
50 .SH 説明
51 \fBsignal\fP()  の動作は UNIX のバージョンにより異なる。 また、歴史的に見て Linux のバージョンによっても異なっている。
52 \fBこのシステムコールの使用は避け、\fP 代わりに \fBsigaction\fP(2)  を使用すること。 下記の「移植性」を参照。
53
54 \fBsignal\fP()  はシグナル \fIsignum\fP の処理方法を \fIhandler\fP に設定する。 \fIhandler\fP には、
55 \fBSIG_IGN\fP、 \fBSIG_DFL\fP、 プログラマが定義した関数 (「シグナル・ハンドラ」) のアドレスの いずれかを指定する。
56
57 シグナル \fIsignum\fP がプロセスに配送されると、以下のいずれかが発生する。
58 .TP  3
59 *
60 処理方法が \fBSIG_IGN\fP に設定されている場合、そのシグナルは無視される。
61 .TP 
62 *
63 処理方法が \fBSIG_DFL\fP に設定されている場合、シグナルに関連づけられた デフォルトの動作が行われる (\fBsignal\fP(7)  参照)。
64 .TP 
65 *
66 処理方法として関数が設定されている場合、 まず最初に処理方法が \fBSIG_DFL\fP にリセットされるかそのシグナルのブロックが実行された後、
67 \fIsignum\fP を引き数として \fIhandler\fP が呼び出される。 ハンドラが起動される際にシグナルがブロックされた場合、
68 ハンドラが返る際にそのシグナルのブロックが解除される。
69 .PP
70 シグナル \fBSIGKILL\fP と \fBSIGSTOP\fP は捕捉できず、無視することもできない。
71 .SH 返り値
72 \fBsignal\fP()  は、今までのシグナル・ハンドラの値を返す。エラーの場合は \fBSIG_ERR\fP を返す。
73 .SH エラー
74 .TP 
75 \fBEINVAL\fP
76 \fIsignum\fP が不正である。
77 .SH 準拠
78 C89, C99, POSIX.1\-2001.
79 .SH 注意
80 マルチスレッドプロセスにおける \fBsignal\fP()  の結果は、指定されていない。
81 .PP
82 POSIX では、 \fBkill\fP(2)  や \fBraise\fP(3)  で生成できないシグナル \fBSIGFPE\fP, \fBSIGILL\fP,
83 \fBSIGSEGV\fP を無視 (ignore) した場合、その後の動作は未定義である。 ゼロによる整数割り算の結果は未定義となる。
84 アーキテクチャーによっては、このとき \fBSIGFPE\fP シグナルが生成される。 (同様に負の最大整数を \-1 で割ると \fBSIGFPE\fP
85 が生成されるかもしれない)  このシグナルを無視すると無限ループに陥るかもしれない。
86 .PP
87 \fBSIGCHLD\fP の動作として \fBSIG_IGN\fP を設定した場合の詳細な動作については、 \fBsigaction\fP(2)  を参照すること。
88 .PP
89 シグナル・ハンドラ内から安全に呼び出すことができる、 async\-signal\-safe functions (非同期シングルで安全な関数) の
90 リストについては \fBsignal\fP(7)  を参照。
91 .PP
92 .\" libc4 and libc5 define
93 .\" .IR SignalHandler ;
94 \fIsighandler_t\fP の使用は GNU 拡張であり、 \fB_GNU_SOURCE\fP が定義された
95 場合に公開される。glibc では \fB_BSD_SOURCE\fP が定義された場合には (BSD
96 由来の) \fIsig_t\fP も定義される。このような型を使用しないと、
97 \fBsignal\fP() の宣言は読みにくいものとなる。
98 .in +4n
99 .nf
100
101 \fBvoid ( *\fP\fIsignal\fP\fB(int \fP\fIsignum\fP\fB, void (*\fP\fIhandler\fP\fB)(int)) ) (int);\fP
102 .fi
103 .in
104 .SS 移植性
105 移植性のある \fBsignal\fP()  の使い方は、シグナルの処理方法を \fBSIG_DFL\fP か \fBSIG_IGN\fP に設定する方法だけである。
106 シグナル・ハンドラを設定するのに \fBsignal\fP()  を使ったときの動作はシステムにより異なる (POSIX.1
107 は明示的にこの違いを認めている)。 \fB移植性が必要なときはこのシステムコールを使用しないこと。\fP
108
109 POSIX.1 は、 \fBsigaction\fP(2)  を規定することで移植性に関する混乱を解決した。 \fBsigaction\fP(2)
110 はシグナル・ハンドラが起動される際の挙動を明示的に制御できる。 \fBsignal\fP()  の代わりにこのインターフェイスを使うこと。
111
112 In the original UNIX systems, when a handler that was established using
113 \fBsignal\fP()  was invoked by the delivery of a signal, the disposition of the
114 signal would be reset to \fBSIG_DFL\fP, and the system did not block delivery
115 of further instances of the signal.  This is equivalent to calling
116 \fBsigaction\fP(2)  with the following flags:
117
118     sa.sa_flags = SA_RESETHAND | SA_NODEFER;
119
120 System V also provides these semantics for \fBsignal\fP().  This was bad
121 because the signal might be delivered again before the handler had a chance
122 to reestablish itself.  Furthermore, rapid deliveries of the same signal
123 could result in recursive invocations of the handler.
124
125 BSD improved on this situation, but unfortunately also changed the semantics
126 of the existing \fBsignal\fP()  interface while doing so.  On BSD, when a
127 signal handler is invoked, the signal disposition is not reset, and further
128 instances of the signal are blocked from being delivered while the handler
129 is executing.  Furthermore, certain blocking system calls are automatically
130 restarted if interrupted by a signal handler (see \fBsignal\fP(7)).  The BSD
131 semantics are equivalent to calling \fBsigaction\fP(2)  with the following
132 flags:
133
134     sa.sa_flags = SA_RESTART;
135
136 Linux での状況は以下の通りである。
137 .IP * 2
138 カーネルの \fBsignal\fP()  システムコールは System V 方式を提供している。
139 .IP *
140 デフォルトでは、glibc 2 以降では、 \fBsignal\fP()  ラッパー関数はカーネルのシステムコールを起動しない。 代わりに、ラッパー関数は
141 BSD 方式を示すフラグを使って \fBsigaction\fP(2)  を呼び出す。 機能検査マクロ \fB_BSD_SOURCE\fP
142 を定義していれば、このデフォルトの動作となる。 デフォルトでは、 \fB_BSD_SOURCE\fP が定義される。 \fB_BSD_SOURCE\fP は
143 \fB_GNU_SOURCE\fP が定義された場合には暗黙のうちに定義され、 もちろん明示的に定義することもできる。
144 .sp
145 .\"
146 .\" System V semantics are also provided if one uses the separate
147 .\" .BR sysv_signal (3)
148 .\" function.
149 glibc 2 以降では、機能検査マクロ \fB_BSD_SOURCE\fP が定義されていなければ、 \fBsignal\fP()  は System V
150 方式となる。 (\fBgcc\fP(1)  が標準指定モード (\fI\-std=xxx\fP or \fI\-ansi\fP)  で起動された場合、もしくは
151 \fB_POSIX_SOURCE\fP, \fB_XOPEN_SOURCE\fP, \fB_SVID_SOURCE\fP
152 といった他の様々な機能検査マクロが定義された場合、 デフォルトの \fB_BSD_SOURCE\fP の暗黙の定義は行われない。
153 \fBfeature_test_macros\fP(7)  を参照のこと。)
154 .IP *
155 Linux の libc4 と libc5 の \fBsignal\fP()  関数は System V 方式である。 libc5 システムにおいて
156 \fI<signal.h>\fP のかわりに \fI<bsd/signal.h>\fP をインクルードすると、
157 \fBsignal\fP()  は \fB__bsd_signal\fP()  に再定義され、 \fBsignal\fP()  は BSD 方式となる。
158 .SH 関連項目
159 \fBkill\fP(1), \fBalarm\fP(2), \fBkill\fP(2), \fBkillpg\fP(2), \fBpause\fP(2),
160 \fBsigaction\fP(2), \fBsignalfd\fP(2), \fBsigpending\fP(2), \fBsigprocmask\fP(2),
161 \fBsigsuspend\fP(2), \fBbsd_signal\fP(3), \fBraise\fP(3), \fBsiginterrupt\fP(3),
162 \fBsigqueue\fP(3), \fBsigsetops\fP(3), \fBsigvec\fP(3), \fBsysv_signal\fP(3),
163 \fBsignal\fP(7)
164 .SH この文書について
165 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
166 である。プロジェクトの説明とバグ報告に関する情報は
167 http://www.kernel.org/doc/man\-pages/ に書かれている。