OSDN Git Service

6a4fd17063e6da02579c06cc102b94736fafa626
[linuxjm/LDP_man-pages.git] / release / man2 / kill.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\"
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 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified by Thomas Koenig <ig25@rz.uni-karlsruhe.de>
27 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1993-07-25 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified 1995-11-01 by Michael Haardt
30 .\"  <michael@cantor.informatik.rwth-aachen.de>
31 .\" Modified 1996-04-14 by Andries Brouwer <aeb@cwi.nl>
32 .\"  [added some polishing contributed by Mike Battersby <mib@deakin.edu.au>]
33 .\" Modified 1996-07-21 by Andries Brouwer <aeb@cwi.nl>
34 .\" Modified 1997-01-17 by Andries Brouwer <aeb@cwi.nl>
35 .\" Modified 2001-12-18 by Andries Brouwer <aeb@cwi.nl>
36 .\" Modified 2002-07-24 by Michael Kerrisk <mtk.manpages@gmail.com>
37 .\"     Added note on historical rules enforced when an unprivileged process
38 .\"     sends a signal.
39 .\" Modified 2004-06-16 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\"     Added note on CAP_KILL
41 .\" Modified 2004-06-24 by aeb
42 .\" Modified, 2004-11-30, after idea from emmanuel.colbus@ensimag.imag.fr
43 .\"
44 .\" Japanese Version Copyright (c) 1997 Kazuyuki Tanisako
45 .\"         all rights reserved.
46 .\" Translated 1997-05-17, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
47 .\" Modified 1997-05-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
48 .\" Modified 1998-02-05, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
49 .\" Updated 2001-12-27, Kentaro Shirakata <argrath@ub32.org>
50 .\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
51 .\" Updated 2002-09-27, Kentaro Shirakata <argrath@ub32.org>
52 .\" Updated 2005-02-27, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
53 .\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16
54 .\" Updated 2008-08-06, Akihiro MOTOKI, LDP v3.05
55 .\"
56 .\"WORD:        signal                  シグナル
57 .\"WORD:        process group           プロセス・グループ
58 .\"WORD:        permission              許可
59 .\"WORD:        privileges              特権
60 .\"WORD:        set-user-id             セットユーザーID
61 .\"WORD:        signal handler          シグナルハンドラー
62 .\"
63 .TH KILL 2 2009-09-15 "Linux" "Linux Programmer's Manual"
64 .SH 名前
65 kill \- プロセスにシグナルを送る
66 .SH 書式
67 .nf
68 .B #include <sys/types.h>
69 .br
70 .B #include <signal.h>
71 .sp
72 .BI "int kill(pid_t " pid ", int " sig );
73 .fi
74 .sp
75 .in -4n
76 glibc 向けの機能検査マクロの要件
77 .RB ( feature_test_macros (7)
78 参照):
79 .in
80 .sp
81 .ad l
82 .BR kill ():
83 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
84 .ad b
85 .SH 説明
86 システムコールの
87 .BR kill ()
88 は、任意のプロセス・グループもしくはプロセスにシグナルを
89 送るのに使われる。
90 .PP
91 \fIpid\fP に正の値を指定した場合、シグナル \fIsig\fP が
92 \fIpid\fP で指定された ID を持つプロセスに送られる。
93 .PP
94 \fIpid\fP に 0 を指定した場合、
95 呼び出し元のプロセスのプロセス・グループに属するすべてのプロセスに
96 \fIsig\fP で指定したシグナルが送られる。
97 .PP
98 \fIpid\fP に \-1 を指定した場合、 \fIsig\fP で指定したシグナルが、
99 呼び出し元のプロセスがシグナルを送る許可を持つ全てのプロセスに
100 送られる。但し、プロセス番号 1 (\fIinit\fP) へはシグナルは送られない。
101 以下の関連部分も参照のこと。
102 .PP
103 \fIpid\fP に \-1 より小さな値を指定した場合、
104 ID が \fI\-pid\fP のプロセス・グループに属するすべてのプロセスに
105 \fIsig\fP で指定したシグナルが送られる。
106 .PP
107 \fIsig\fP に 0 を指定した場合、シグナルは送られないが、
108 エラーのチェックは行われる。これを使って、プロセス ID や
109 プロセスグループ ID の存在確認を行うことができる。
110
111 あるプロセスがシグナルを送る許可を持つには、
112 そのプロセスが特権 (Linux では
113 .B CAP_KILL
114 ケーパビリティ) を持つプロセスであるか、シグナルを送る側のプロセスの
115 実UID か実効UID が受ける側のプロセスの実 set-UID か
116 保存 (saved) set-UID が一致していなければならない。
117 .B SIGCONT
118 の場合は、シグナルを送信するプロセスと受信するプロセスが
119 同じセッションに所属していれば十分である。
120 .SH 返り値
121 成功した場合 (少なくとも一つのシグナルが送信された場合)、
122 0 が返される。エラーの場合 \-1 が返され、
123 .I errno
124 が適切に設定される。
125 .SH エラー
126 .TP
127 .B EINVAL
128 無効なシグナルを指定した。
129 .TP
130 .B EPERM
131 プロセスが、受信するプロセスのいずれに対しても
132 シグナルを送る許可を持っていない。
133 .TP
134 .B ESRCH
135 指定したプロセスまたはプロセス・グループが存在しなかった。
136 ゾンビプロセスは存在するプロセスとしてみなされる。
137 ゾンビプロセスとはすでに処理は終了しているが、親プロセスによる
138 .BR wait ()
139 処理が行われていないプロセスのことである。
140 .SH 準拠
141 SVr4, 4.3BSD, POSIX.1-2001.
142 .SH 注意
143 プロセス番号 1 の
144 .I init
145 プロセスに送ることができるシグナルは、
146 .I init
147 が明示的にシグナルハンドラを設定したシグナルだけである。
148 こうなっているのは、誤ってシステムをダウンさせないようにするためである。
149 .LP
150 POSIX.1-2001 では、 \fIkill(\-1,sig)\fP が
151 呼び出し元のプロセスがシグナルを送ることが出来るプロセス全てに
152 \fIsig\fP を送ることを要求している。
153 但し、システム実装時に定められたシステムプロセスは
154 シグナルの送信対象から除外される。
155 Linux では、プロセスが自分自身にシグナルを送れるようになっているが、
156 Linux の \fIkill(\-1,sig)\fP は呼び出し元のプロセスにはシグナルを送らない。
157 .LP
158 POSIX.1-2001 では以下の動作になることを要求している。
159 自分自身にシグナルを送ると、シグナルを送ったスレッドがそのシグナルをブロック
160 しておらず、他のどのスレッドもそのシグナルを受ける状態にもなく
161 .BR sigwait (3)
162 でそのシグナルを待ってもいない場合、
163 .BR kill ()
164 が返る前に少なくとも一つのブロックされていない
165 シグナルがシグナルを送ったスレッドに配送されなければならない。
166 .SS "Linux での注意"
167 Linux では、特権のないプロセスが他のプロセスにシグナルを送信するために
168 必要な権限についてのルールが、カーネルバージョンにより違っている。
169 .\" 0.* カーネルの話は割愛し、多少変更した。- MTK, 24 Jul 02
170 カーネル 1.0 から 1.2.2 では、送信側の実効ユーザーID が受信側の
171 実効ユーザー IDと一致すればシグナルを送信できた。
172 カーネル 1.2.3 から 1.3.77では、送信側の実効ユーザーID が受信側の
173 実ユーザーID か実効ユーザーID のいずれかと一致すればシグナルを送信できた。
174 現在のルールは、POSIX.1-2001 に準拠しており、カーネル 1.3.78 以降で
175 適用されている。
176 .SH バグ
177 バージョン 2.6.7 以前の 2.6 系のカーネルには、
178 プロセスグループにシグナルを送ったときに、
179 呼び出し元のプロセスがプロセスグループの (全メンバーではなく) 一部のメンバー
180 に対してのみシグナルを送る許可を持っている場合に、
181 .BR kill ()
182 がエラー
183 .B EPERM
184 で失敗するというバグがある。
185 このエラーが返るにもかかわらず、そのシグナルは呼び出し元が
186 シグナルを送る許可を持つ全てのプロセスへ送られる。
187 .SH 関連項目
188 .BR _exit (2),
189 .BR killpg (2),
190 .BR signal (2),
191 .BR tkill (2),
192 .BR exit (3),
193 .BR sigqueue (3),
194 .BR credentials (7),
195 .BR capabilities (7),
196 .BR signal (7)