OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man2 / wait.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1993 by Thomas Koenig <ig25@rz.uni-karlsruhe.de>
4 .\" and Copyright (c) 2004 by Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" License.
26 .\"
27 .\" Modified Sat Jul 24 13:30:06 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sun Aug 21 17:42:42 1994 by Rik Faith <faith@cs.unc.edu>
29 .\"          (Thanks to Koen Holtman <koen@win.tue.nl>)
30 .\" Modified Wed May 17 15:54:12 1995 by Rik Faith <faith@cs.unc.edu>
31 .\"           To remove *'s from status in macros (Thanks to Michael Shields).
32 .\" Modified as suggested by Nick Duffek <nsd@bbc.com>, aeb, 960426
33 .\" Modified Mon Jun 23 14:09:52 1997 by aeb - add EINTR.
34 .\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff.
35 .\" Modified Mon Jul 24 21:37:38 2000 by David A. Wheeler
36 .\"          <dwheeler@dwheeler.com> - noted thread issues.
37 .\" Modified 26 Jun 01 by Michael Kerrisk
38 .\"          Added __WCLONE, __WALL, and __WNOTHREAD descriptions
39 .\" Modified 2001-09-25, aeb
40 .\" Modified 26 Jun 01 by Michael Kerrisk, <mtk.manpages@gmail.com>
41 .\"     Updated notes on setting disposition of SIGCHLD to SIG_IGN
42 .\" 2004-11-11, mtk
43 .\"     Added waitid(2); added WCONTINUED and WIFCONTINUED()
44 .\"     Added text on SA_NOCLDSTOP
45 .\"     Updated discussion of SA_NOCLDWAIT to reflect 2.6 behavior
46 .\"     Much other text rewritten
47 .\" 2005-05-10, mtk, __W* flags can't be used with waitid()
48 .\" 2008-07-04, mtk, removed erroneous text about SA_NOCLDSTOP
49 .\"
50 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya all rights reserved.
51 .\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved.
52 .\" Translated 1997-03-04, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
53 .\" Modified 2000-09-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
54 .\" Updated 2001-06-25, Kentaro Shirakata <argrath@ub32.org>
55 .\" Updated 2001-10-15, Kentaro Shirakata <argrath@ub32.org>
56 .\" Updated 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
57 .\" Updated 2002-10-21, Kentaro Shirakata <argrath@ub32.org>
58 .\" Updated 2003-01-27, Kentaro Shirakata <argrath@ub32.org>
59 .\" Updated 2003-09-12, Kentaro Shirakata <argrath@ub32.org>
60 .\" Updated 2005-03-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
61 .\" Updated 2005-12-26, Akihiro MOTOKI
62 .\" Updated 2008-07-31, Akihiro MOTOKI, LDP v3.05
63 .\"
64 .\"WORD:        signal handling         ¥·¥°¥Ê¥ë½èÍý
65 .\"WORD:        suspend                 Ää»ß(suspend)
66 .\"WORD:        zombie                  ¥¾¥ó¥Ó(zombie)
67 .\"WORD:        child process           »Ò¥×¥í¥»¥¹
68 .\"WORD:        process group           ¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×
69 .\"WORD:        process group ID        ¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×ID
70 .\"WORD:        stop                    Ää»ß(stop)
71 .\"WORD:        effective user ID       ¼Â¸ú¥æ¡¼¥¶¡¼ID
72 .\"WORD:        block                   ¶Ø»ß(block)
73 .\"
74 .TH WAIT 2 2010-09-26 "Linux" "Linux Programmer's Manual"
75 .\"O .SH NAME
76 .SH Ì¾Á°
77 .\"O wait, waitpid, waitid \- wait for process to change state
78 wait, waitpid, waitid \- ¥×¥í¥»¥¹¤Î¾õÂÖÊѲ½¤òÂÔ¤Ä
79 .\"O .SH SYNOPSIS
80 .SH ½ñ¼°
81 .B #include <sys/types.h>
82 .br
83 .B #include <sys/wait.h>
84 .sp
85 .BI "pid_t wait(int *" "status" );
86
87 .BI "pid_t waitpid(pid_t " pid ", int *" status ", int " options );
88
89 .BI "int waitid(idtype_t " idtype ", id_t " id \
90 ", siginfo_t *" infop ", int " options );
91 .sp
92 .in -4n
93 .\"O Feature Test Macro Requirements for glibc (see
94 .\"O .BR feature_test_macros (7)):
95 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
96 .RB ( feature_test_macros (7)
97 »²¾È):
98 .in
99 .sp
100 .ad l
101 .PD 0
102 .BR waitid ():
103 .RS 4
104 _SVID_SOURCE ||
105 _XOPEN_SOURCE\ >=\ 500 ||
106 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
107 .br
108 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
109 || /* glibc 2.12 °Ê¹ß: */ _POSIX_C_SOURCE\ >=\ 200809L
110 .RE
111 .PD
112 .ad
113 .\"O .SH DESCRIPTION
114 .SH ÀâÌÀ
115 .\"O All of these system calls are used to wait for state changes
116 .\"O in a child of the calling process, and obtain information
117 .\"O about the child whose state has changed.
118 .\"O A state change is considered to be: the child terminated;
119 .\"O the child was stopped by a signal; or the child was resumed by a signal.
120 .\"O In the case of a terminated child, performing a wait allows
121 .\"O the system to release the resources associated with the child;
122 .\"O if a wait is not performed, then the terminated child remains in
123 .\"O a "zombie" state (see NOTES below).
124 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¤¤¤º¤ì¤â¡¢¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î»Ò¥×¥í¥»¥¹¤Î
125 ¾õÂÖÊѲ½¤òÂÔ¤Á¡¢¾õÂÖ¤¬ÊѲ½¤·¤¿¤½¤Î»Ò¥×¥í¥»¥¹¤Î¾ðÊó¤ò¼èÆÀ¤¹¤ë¤Î¤Ë
126 »ÈÍѤµ¤ì¤ë¡£
127 ¾õÂÖÊѲ½¤È¤Ï°Ê²¼¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë:
128 »Ò¥×¥í¥»¥¹¤Î½ªÎ»¡¢¥·¥°¥Ê¥ë¤Ë¤è¤ë»Ò¥×¥í¥»¥¹¤ÎÄä»ß¡¢
129 ¥·¥°¥Ê¥ë¤Ë¤è¤ë»Ò¥×¥í¥»¥¹¤ÎºÆ³«¡£
130 »Ò¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿¾ì¹ç¤Ï¡¢wait ¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¡¢
131 ¥·¥¹¥Æ¥à¤¬¤½¤Î»Ò¥×¥í¥»¥¹¤Ë´ØÏ¢¤¹¤ë¥ê¥½¡¼¥¹¤ò²òÊü¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë¡£
132 wait ¤¬¼Â¹Ô¤µ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢½ªÎ»¤·¤¿»Ò¥×¥í¥»¥¹¤Ï
133 ¡Ö¥¾¥ó¥Ó¡×¾õÂ֤ǻĤ곤±¤ë (²¼µ­¤ÎÃí°Õ¤Î¾Ï¤ò»²¾È¤Î¤³¤È)¡£
134
135 .\"O If a child has already changed state, then these calls return immediately.
136 .\"O Otherwise they block until either a child changes state or
137 .\"O a signal handler interrupts the call (assuming that system calls
138 .\"O are not automatically restarted using the
139 .\"O .B SA_RESTART
140 .\"O flag of
141 .\"O .BR sigaction (2)).
142 .\"O In the remainder of this page, a child whose state has changed
143 .\"O and which has not yet been waited upon by one of these system
144 .\"O calls is termed
145 .\"O .IR waitable .
146 »Ò¥×¥í¥»¥¹¤Î¾õÂÖÊѲ½¤¬¤¹¤Ç¤ËȯÀ¸¤·¤Æ¤¤¤¿¾ì¹ç¡¢¤³¤ì¤é¤Î¥³¡¼¥ë¤Ï
147 ¤¹¤°¤ËÉüµ¢¤¹¤ë¡£¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¡¢»Ò¥×¥í¥»¥¹¤Î¾õÂÖÊѲ½¤¬µ¯¤³¤ë¤«¡¢
148 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬ÃæÃǤµ¤ì¤ë¤Þ¤Ç¡¢
149 Ää»ß (block) ¤¹¤ë (¸å¼Ô¤Ï¡¢
150 .BR sigaction (2)
151 ¤Î
152 .B SA_RESTART
153 ¥Õ¥é¥°¤Ë¤è¤ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬¼«Æ°Åª¤ËºÆ¥¹¥¿¡¼¥È¤¹¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Ê¤¤
154 ¾ì¹ç¤ÎÆ°ºî¤Ç¤¢¤ë)¡£
155 °Ê²¼¤ÎÀâÌÀ¤Ç¤Ï¡¢¾õÂÖÊѲ½¤¬µ¯¤³¤Ã¤¿¤¬¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¤¤¤º¤ì¤«¤Ë
156 ¤è¤Ã¤ÆÂÔ¤¿¤ì¤Æ¤¤¤Ê¤¤»Ò¥×¥í¥»¥¹¤ò
157 .I waitable
158 (ÂÔ¤Á²Äǽ) ¤È¸Æ¤Ö¡£
159 .\"O .SS "wait() and waitpid()"
160 .SS "wait() ¤È waitpid()"
161 .\"O The
162 .\"O .BR wait ()
163 .\"O system call suspends execution of the calling process until one of its
164 .\"O children terminates.
165 .\"O The call
166 .\"O .I wait(&status)
167 .\"O is equivalent to:
168 .\"O .nf
169 .\"O
170 .\"O     watpid(\-1, &status, 0);
171 .\"O .fi
172 .BR wait ()
173 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢»Ò¥×¥í¥»¥¹¤Î¤¤¤º¤ì¤«¤¬½ªÎ»¤¹¤ë¤Þ¤Ç
174 ¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¼Â¹Ô¤ò°ì»þÄä»ß¤¹¤ë¡£
175 °Ê²¼¤ÎÆó¤Ä¤Î¸Æ¤Ó½Ð¤·¤ÏÅù²Á¤Ç¤¢¤ë:
176 .nf
177
178     wait(&status);
179
180     waitpid(\-1, &status, 0);
181 .fi
182
183 .\"O The
184 .\"O .BR waitpid ()
185 .\"O system call suspends execution of the calling process until a
186 .\"O child specified by
187 .\"O .I pid
188 .\"O argument has changed state.
189 .\"O By default,
190 .\"O .BR waitpid ()
191 .\"O waits only for terminated children, but this behavior is modifiable
192 .\"O via the
193 .\"O .I options
194 .\"O argument, as described below.
195 .BR waitpid ()
196 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢
197 .I pid
198 °ú¤­¿ô¤Ç»ØÄꤷ¤¿»Ò¥×¥í¥»¥¹¤Î¾õÂÖÊѲ½¤¬µ¯¤³¤ë¤Þ¤Ç¡¢
199 ¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¼Â¹Ô¤ò°ì»þÄä»ß¤¹¤ë¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢
200 .BR waitpid ()
201 ¤Ï»Ò¥×¥í¥»¥¹¤Î½ªÎ»¤À¤±¤òÂԤĤ¬¡¢¤³¤ÎÆ°ºî¤Ï
202 .I options
203 °ú¤­¿ô¤Ë¤è¤êÊѹ¹²Äǽ¤Ç¤¢¤ë¡£
204
205 .\"O The value of
206 .\"O .I pid
207 .\"O can be:
208 .I pid
209 ¤Ë»ØÄê¤Ç¤­¤ëÃͤϰʲ¼¤ÎÄ̤ê:
210 .IP "< \-1"
211 .\"O meaning wait for any child process whose process group ID is
212 .\"O equal to the absolute value of
213 .\"O .IR pid .
214 ¥×¥í¥»¥¹¥°¥ë¡¼¥×ID ¤¬
215 .I pid
216 ¤ÎÀäÂÐÃͤËÅù¤·¤¤»Ò¥×¥í¥»¥¹¤Î¤¤¤º¤ì¤«¤¬½ªÎ»¤¹¤ë¤Þ¤Ç¤òÂԤġ£
217 .IP \-1
218 .\"O meaning wait for any child process.
219 »Ò¥×¥í¥»¥¹¤Î¤É¤ì¤«¤¬½ªÎ»¤¹¤ë¤Þ¤ÇÂԤġ£
220 .IP 0
221 .\"O meaning wait for any child process whose process group ID is
222 .\"O equal to that of the calling process.
223 ¥×¥í¥»¥¹¥°¥ë¡¼¥×ID ¤¬¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¤â¤Î¤ÈÅù¤·¤¤
224 »Ò¥×¥í¥»¥¹¤òÂԤġ£
225 .IP "> 0"
226 .\"O meaning wait for the child whose process ID is equal to the
227 .\"O value of
228 .\"O .IR pid .
229 ¥×¥í¥»¥¹ID ¤¬
230 .I pid
231 ¤ËÅù¤·¤¤»Ò¥×¥í¥»¥¹¤òÂԤġ£
232 .PP
233 .\"O The value of
234 .\"O .I options
235 .\"O is an OR of zero or more of the following constants:
236 .I options
237 ¤ÎÃͤϼ¡¤ÎÄê¿ô¤Î 0 ¸Ä°Ê¾å¤ÎÏÀÍýϤǤ¢¤ë:
238 .TP 12
239 .B WNOHANG
240 .\"O return immediately if no child has exited.
241 ¾õÂÖÊѲ½¤¬µ¯¤³¤Ã¤¿»Ò¥×¥í¥»¥¹¤¬¤Ê¤¤¾ì¹ç¤Ë¤¹¤°¤ËÉüµ¢¤¹¤ë¡£
242 .TP
243 .B WUNTRACED
244 .\"O also return if a child has stopped
245 .\"O (but not traced via
246 .\"O .BR ptrace (2)).
247 .\"O Status for
248 .\"O .I traced
249 .\"O children which have stopped is provided
250 .\"O even if this option is not specified.
251 »Ò¥×¥í¥»¥¹¤¬Ää»ß¤·¤¿¾ì¹ç¤Ë¤âÉüµ¢¤¹¤ë (»Ò¥×¥í¥»¥¹¤¬
252 .BR ptrace (2)
253 ¤Ç¥È¥ì¡¼¥¹¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï½ü¤¯)¡£
254 ¤³¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ç¤â¡¢Ää»ß¤·¤¿¥×¥í¥»¥¹¤¬
255 ¡Ö¥È¥ì¡¼¥¹ (traced)¡×¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢»Ò¥×¥í¥»¥¹¤Î¾õÂÖ¤¬Êó¹ð¤µ¤ì¤ë¡£
256 .TP
257 .\"O .BR WCONTINUED " (Since Linux 2.6.10)"
258 .BR WCONTINUED " (Linux 2.6.10 °Ê¹ß)"
259 .\"O also return if a stopped child has been resumed by delivery of
260 .\"O .BR SIGCONT .
261 Ää»ß¤·¤¿»Ò¥×¥í¥»¥¹¤¬
262 .B SIGCONT
263 ¤ÎÇÛÁ÷¤Ë¤è¤êºÆ³«¤·¤¿¾ì¹ç¤Ë¤âÉüµ¢¤¹¤ë¡£
264 .PP
265 .\"O (For Linux-only options, see below.)
266 (Linux ÀìÍÑ¥ª¥×¥·¥ç¥ó¤Ë¤Ä¤¤¤Æ¤Ï¸å½Ò¤¹¤ë)
267 .PP
268 .\"O If
269 .\"O .I status
270 .\"O is not NULL,
271 .\"O .BR wait ()
272 .\"O and
273 .\"O .BR waitpid ()
274 .\"O store status information in the \fIint\fP to which it points.
275 .I status
276 ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢
277 .BR wait ()
278 ¤ä
279 .BR waitpid ()
280 ¤Ï
281 .I status
282 ¤Ç»Ø¤¹ \fIint\fP ¤Ë¾õÂÖ¾ðÊó¤ò³ÊǼ¤¹¤ë¡£
283 .\"O This integer can be inspected with the following macros (which
284 .\"O take the integer itself as an argument, not a pointer to it,
285 .\"O as is done in
286 .\"O .BR wait ()
287 .\"O and
288 .\"O .BR waitpid ()!):
289 ¤³¤ÎÀ°¿ô¤Ï°Ê²¼¤Î¥Þ¥¯¥í¤ò»È¤Ã¤Æ¸¡ºº¤Ç¤­¤ë¡£
290 (¤³¤ì¤é¤Î¥Þ¥¯¥í¤Î°ú¤­¿ô¤Ë¤Ï¡¢
291 .BR wait ()
292 ¤ä
293 .BR waitpid ()
294 ¤¬½ñ¤­¹þ¤ó¤ÀÀ°¿ô¤½¤Î¤â¤Î¤ò»ØÄꤹ¤ë¡£¥Ý¥¤¥ó¥¿¤Ç¤Ï¤Ê¤¤!)
295 .TP
296 .BI WIFEXITED( status )
297 .\"O returns true if the child terminated normally, that is,
298 .\"O by calling
299 .\"O .BR exit (3)
300 .\"O or
301 .\"O .BR _exit (2),
302 .\"O or by returning from main().
303 »Ò¥×¥í¥»¥¹¤¬Àµ¾ï¤Ë½ªÎ»¤·¤¿¾ì¹ç¤Ë¿¿¤òÊÖ¤¹¡£
304 ¡ÖÀµ¾ï¤Ë¡×¤È¤Ï¡¢
305 .BR exit (3)
306 ¤«
307 .BR _exit (2)
308 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¾ì¹ç¡¢¤â¤·¤¯¤Ï
309 main() ¤«¤éÉüµ¢¤·¤¿¾ì¹ç¤Ç¤¢¤ë¡£
310 .TP
311 .BI WEXITSTATUS( status )
312 .\"O returns the exit status of the child.
313 .\"O This consists of the least significant 8 bits of the
314 .\"O .I status
315 .\"O argument that the child specified in a call to
316 .\"O .BR exit (3)
317 .\"O or
318 .\"O .BR _exit (2)
319 .\"O or as the argument for a return statement in main().
320 .\"O This macro should only be employed if
321 .\"O .B WIFEXITED
322 .\"O returned true.
323 »Ò¥×¥í¥»¥¹¤Î½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤òÊÖ¤¹¡£
324 ½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤Ï
325 .I status
326 °ú¤­¿ô¤Î²¼°Ì 8¥Ó¥Ã¥È¤Ç¹½À®¤µ¤ì¤Æ¤ª¤ê¡¢
327 .BR exit (3)
328 ¤ä
329 .BR _exit (2)
330 ¤Î¸Æ¤Ó½Ð¤·»þ¤ËÅϤµ¤ì¤¿ÃÍ¡¢¤â¤·¤¯¤Ï main() ¤Î return Ê¸¤Î
331 °ú¤­¿ô¤È¤·¤Æ»ØÄꤵ¤ì¤¿ÃͤǤ¢¤ë¡£
332 ¤³¤Î¥Þ¥¯¥í¤ò»ÈÍѤ¹¤ë¤Î¤Ï
333 .B WIFEXITED
334 ¤¬¿¿¤òÊÖ¤·¤¿¾ì¹ç¤À¤±¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
335 .TP
336 .BI WIFSIGNALED( status )
337 .\"O returns true if the child process was terminated by a signal.
338 »Ò¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤Ë¤è¤ê½ªÎ»¤·¤¿¾ì¹ç¤Ë¿¿¤òÊÖ¤¹¡£
339 .TP
340 .BI WTERMSIG( status )
341 .\"O returns the number of the signal that caused the child process to
342 .\"O terminate.
343 .\"O This macro should only be employed if
344 .\"O .B WIFSIGNALED
345 .\"O returned true.
346 »Ò¥×¥í¥»¥¹½ªÎ»¤Î¸¶°ø¤È¤Ê¤Ã¤¿¥·¥°¥Ê¥ë¤ÎÈÖ¹æ¤òÊÖ¤¹¡£
347 ¤³¤Î¥Þ¥¯¥í¤ò»ÈÍѤ¹¤ë¤Î¤Ï
348 .B WIFSIGNALED
349 ¤¬¿¿¤òÊÖ¤·¤¿¾ì¹ç¤À¤±¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
350 .TP
351 .BI WCOREDUMP( status )
352 .\"O returns true if the child produced a core dump.
353 .\"O This macro should only be employed if
354 .\"O .B WIFSIGNALED
355 .\"O returned true.
356 .\"O This macro is not specified in POSIX.1-2001 and is not available on
357 .\"O some UNIX implementations (e.g., AIX, SunOS).
358 .\"O Only use this enclosed in #ifdef WCOREDUMP ... #endif.
359 »Ò¥×¥í¥»¥¹¤¬¥³¥¢¥À¥ó¥×¤òÀ¸À®¤·¤¿¾ì¹ç¤Ë¿¿¤òÊÖ¤¹¡£
360 ¤³¤Î¥Þ¥¯¥í¤ò»ÈÍѤ¹¤ë¤Î¤Ï
361 .B WIFSIGNALED
362 ¤¬¿¿¤òÊÖ¤·¤¿¾ì¹ç¤À¤±¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
363 ¤³¤Î¥Þ¥¯¥í¤Ï POSIX.1-2001 ¤Ç¤Ïµ¬Äꤵ¤ì¤Æ¤ª¤é¤º¡¢
364 (AIX, SunOS ¤Ê¤É¤Î) ¤¤¤¯¤Ä¤«¤Î UNIX ¤Î¼ÂÁõ¤Ç¤ÏÍøÍѤǤ­¤Ê¤¤¡£
365 ɬ¤º #ifdef WCOREDUMP ... #endif ¤Ç³ç¤Ã¤Æ»ÈÍѤ¹¤ë¤³¤È¡£
366 .TP
367 .BI WIFSTOPPED( status )
368 .\"O returns true if the child process was stopped by delivery of a signal;
369 .\"O this is only possible if the call was done using
370 .\"O .B WUNTRACED
371 .\"O or when the child is being traced (see
372 .\"O .BR ptrace (2)).
373 »Ò¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤ÎÇÛÁ÷¤Ë¤è¤êÄä»ß¤·¤¿¾ì¹ç¤Ë¿¿¤òÊÖ¤¹¡£
374 ¤³¤ì¤¬¿¿¤Ë¤Ê¤ë¤Î¤Ï¡¢¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬
375 .B WUNTRACED
376 ¤ò»ØÄꤷ¤Æ¸Æ¤Ó½Ð¤µ¤ì¤¿¾ì¹ç¤«¡¢»Ò¥×¥í¥»¥¹¤¬¥È¥ì¡¼¥¹¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
377 .RB ( ptrace (2)
378 »²¾È) ¤À¤±¤Ç¤¢¤ë¡£
379 .TP
380 .BI WSTOPSIG( status )
381 .\"O returns the number of the signal which caused the child to stop.
382 .\"O This macro should only be employed if
383 .\"O .B WIFSTOPPED
384 .\"O returned true.
385 »Ò¥×¥í¥»¥¹¤òÄä»ß¤µ¤»¤¿¥·¥°¥Ê¥ë¤ÎÈÖ¹æ¤òÊÖ¤¹¡£
386 ¤³¤Î¥Þ¥¯¥í¤ò»ÈÍѤ¹¤ë¤Î¤Ï
387 .B WIFSTOPPED
388 ¤¬ 0 °Ê³°¤òÊÖ¤·¤¿¾ì¹ç¤À¤±¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
389 .TP
390 .BI WIFCONTINUED( status )
391 .\"O (since Linux 2.6.10)
392 (Linux 2.6.10 °Ê¹ß)
393 .\"O returns true if the child process was resumed by delivery of
394 .\"O .BR SIGCONT .
395 »Ò¥×¥í¥»¥¹¤¬
396 .B SIGCONT
397 ¤ÎÇÛÁ÷¤Ë¤è¤êºÆ³«¤·¤¿¾ì¹ç¤Ë¿¿¤òÊÖ¤¹¡£
398 .SS "waitid()"
399 .\"O The
400 .\"O .BR waitid ()
401 .\"O system call (available since Linux 2.6.9) provides more precise
402 .\"O control over which child state changes to wait for.
403 .BR waitid ()
404 ¥·¥¹¥Æ¥à¥³¡¼¥ë (Linux 2.6.9 °Ê¹ß¤ÇÍøÍѲÄǽ) ¤ò»È¤¦¤È¡¢
405 »Ò¥×¥í¥»¥¹¤Î¤É¤Î¾õÂÖÊѲ½¤òÂԤĤ«¤Ë¤Ä¤¤¤Æ¤è¤êºÙ¤«¤ÊÀ©¸æ¤¬¤Ç¤­¤ë¡£
406
407 .\"O The
408 .\"O .I idtype
409 .\"O and
410 .\"O .I id
411 .\"O arguments select the child(ren) to wait for, as follows:
412 °ú¤­¿ô
413 .I idtype
414 ¤È
415 .I id
416 ¤Ç¤É¤Î»Ò¥×¥í¥»¥¹¤òÂԤĤ«¤òÁªÂò¤¹¤ë:
417 .IP "\fIidtype\fP == \fBP_PID\fP"
418 .\"O Wait for the child whose process ID matches
419 .\"O .IR id .
420 ¥×¥í¥»¥¹ID ¤¬
421 .I id
422 ¤È°ìÃפ¹¤ë»Ò¥×¥í¥»¥¹¤òÂԤġ£
423 .IP "\fIidtype\fP == \fBP_PGID\fP"
424 .\"O Wait for any child whose process group ID matches
425 .\"O .IR id .
426 ¥×¥í¥»¥¹¥°¥ë¡¼¥×ID ¤¬
427 .I id
428 ¤È°ìÃפ¹¤ë»Ò¥×¥í¥»¥¹¤òÂԤġ£
429 .IP "\fIidtype\fP == \fBP_ALL\fP"
430 .\"O Wait for any child;
431 .\"O .I id
432 .\"O is ignored.
433 »Ò¥×¥í¥»¥¹Á´Éô¤òÂоݤËÂԤġ£
434 .I id
435 ¤Ï̵»ë¤µ¤ì¤ë¡£
436 .PP
437 .\"O The child state changes to wait for are specified by ORing
438 .\"O one or more of the following flags in
439 .\"O .IR options :
440 »Ò¥×¥í¥»¥¹¤Î¤É¤Î¾õÂÖÊѲ½¤òÂԤĤ«¤Ï°Ê²¼¤Î¥Õ¥é¥°¤Ç»ØÄꤹ¤ë
441 .RI ( options
442 ¤Ë¤Ï 1¸Ä°Ê¾å¤Î¥Õ¥é¥°¤ÎÏÀÍýϤò¤È¤Ã¤Æ»ØÄꤹ¤ë):
443 .TP 12
444 .B WEXITED
445 .\"O Wait for children that have terminated.
446 »Ò¥×¥í¥»¥¹¤Î½ªÎ»¤òÂԤġ£
447 .TP
448 .B WSTOPPED
449 .\"O Wait for children that have been stopped by delivery of a signal.
450 »Ò¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤ÎÇÛÁ÷¤Ë¤è¤êÄä»ß¤¹¤ë¤Î¤òÂԤġ£
451 .TP
452 .B WCONTINUED
453 .\"O Wait for (previously stopped) children that have been
454 .\"O resumed by delivery of
455 .\"O .BR SIGCONT .
456 (Ää»ß¤·¤Æ¤¤¤¿) »Ò¥×¥í¥»¥¹¤¬
457 .B SIGCONT
458 ¤¬ÇÛÁ÷¤µ¤ì¤ÆºÆ³«¤¹¤ë¤Î¤òÂԤġ£
459 .PP
460 .\"O The following flags may additionally be ORed in
461 .\"O .IR options :
462 ¤µ¤é¤Ë°Ê²¼¤Î¥Õ¥é¥°¤òÏÀÍýϤηÁ¤Ç
463 .I options
464 ¤Ë»ØÄê¤Ç¤­¤ë:
465 .TP 12
466 .B WNOHANG
467 .\"O As for
468 .\"O .BR waitpid ().
469 .BR waitpid ()
470 ¤ÈƱÍÍ¡£
471 .TP
472 .B WNOWAIT
473 .\"O Leave the child in a waitable state; a later wait call
474 .\"O can be used to again retrieve the child status information.
475 waitable ¾õÂÖ¤Î¥×¥í¥»¥¹¤ò¤½¤Î¤Þ¤Þ¤Ë¤¹¤ë¡£¤³¤Î¸å¤Ç wait ¥³¡¼¥ë¤ò
476 »È¤Ã¤Æ¡¢Æ±¤¸»Ò¥×¥í¥»¥¹¤Î¾õÂÖ¾ðÊó¤ò¤â¤¦°ìÅÙ¼èÆÀ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
477 .PP
478 .\"O Upon successful return,
479 .\"O .BR waitid ()
480 .\"O fills in the following fields of the
481 .\"O .I siginfo_t
482 .\"O structure pointed to by
483 .\"O .IR infop :
484 À®¸ù¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
485 .BR waitid ()
486 ¤Ï
487 .I infop
488 ¤¬»Ø¤¹
489 .I siginfo_t
490 ¹½Â¤ÂΤΰʲ¼¤Î¥Õ¥£¡¼¥ë¥É¤òÀßÄꤹ¤ë:
491 .TP 12
492 \fIsi_pid\fP
493 .\"O The process ID of the child.
494 »Ò¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ID¡£
495 .TP
496 \fIsi_uid\fP
497 .\"O The real user ID of the child.
498 .\"O (This field is not set on most other implementations.)
499 »Ò¥×¥í¥»¥¹¤Î¼Â¥æ¡¼¥¶ID
500 (¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¾¤Î¤Û¤È¤ó¤É¤Î¼ÂÁõ¤Ç¤ÏÀßÄꤵ¤ì¤Ê¤¤)¡£
501 .TP
502 \fIsi_signo\fP
503 .\"O Always set to
504 .\"O .BR SIGCHLD .
505 ¾ï¤Ë
506 .B SIGCHLD
507 ¤¬ÀßÄꤵ¤ì¤ë¡£
508 .TP
509 \fIsi_status\fP
510 .\"O Either the exit status of the child, as given to
511 .\"O .BR _exit (2)
512 .\"O (or
513 .\"O .BR exit (3)),
514 .\"O or the signal that caused the child to terminate, stop, or continue.
515 .\"O The
516 .\"O .I si_code
517 .\"O field can be used to determine how to interpret this field.
518 .BR _exit (2)
519 (¤«
520 .BR exit (3))
521 ¤Ë»ØÄꤵ¤ì¤¿»Ò¥×¥í¥»¥¹¤Î½ªÎ»¥¹¥Æ¡¼¥¿¥¹¡¢¤â¤·¤¯¤Ï
522 »Ò¥×¥í¥»¥¹¤Î½ªÎ»¡¢Ää»ß¡¢ºÆ³«¤Î¸¶°ø¤È¤Ê¤Ã¤¿¥·¥°¥Ê¥ë¤¬ÀßÄꤵ¤ì¤ë¡£
523 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤ò¤É¤¦²ò¼á¤¹¤ë¤«¤Ï¡¢
524 .I si_code
525 ¥Õ¥£¡¼¥ë¥É¤ò»²¾È¤·¤Æ·è¤á¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
526 .TP
527 \fIsi_code\fP
528 .\"O Set to one of:
529 .\"O .B CLD_EXITED
530 .\"O (child called
531 .\"O .BR _exit (2));
532 .\"O .B CLD_KILLED
533 .\"O (child killed by signal);
534 .\"O .B CLD_DUMPED
535 .\"O (child killed by signal, and dumped core);
536 .\"O .B CLD_STOPPED
537 .\"O (child stopped by signal);
538 .\"O .B CLD_TRAPPED
539 .\"O (traced child has trapped); or
540 .\"O .B CLD_CONTINUED
541 .\"O (child continued by
542 .\"O .BR SIGCONT ).
543 °Ê²¼¤Î¤¤¤º¤ì¤«¤¬ÀßÄꤵ¤ì¤ë:
544 .B CLD_EXITED
545 (»Ò¥×¥í¥»¥¹¤¬
546 .BR _exit (2)
547 ¤ò¸Æ¤Ó½Ð¤·¤¿);
548 .B CLD_KILLED
549 (¥·¥°¥Ê¥ë¤Ë¤è¤ê»Ò¥×¥í¥»¥¹¤¬ kill ¤µ¤ì¤¿);
550 .B CLD_DUMPED
551 (¥·¥°¥Ê¥ë¤Ë¤è¤ê»Ò¥×¥í¥»¥¹¤¬ kill ¤µ¤ì¡¢¥³¥¢¡¦¥À¥ó¥×¤¬¹Ô¤ï¤ì¤¿);
552 .B CLD_STOPPED
553 (¥·¥°¥Ê¥ë¤Ë¤è¤ê»Ò¥×¥í¥»¥¹¤¬Ää»ß¤·¤¿);
554 .BR CLD_TRAPPED
555 (¥È¥ì¡¼¥¹¤µ¤ì¤Æ¤¤¤¿»Ò¥×¥í¥»¥¹¤¬¥È¥é¥Ã¥×¤ò¼õ¿®¤·¤¿);
556 .B CLD_CONTINUED
557 .RB ( SIGCONT
558 ¤Ë¤è¤ê»Ò¥×¥í¥»¥¹¤¬ºÆ³«¤µ¤ì¤¿)¡£
559 .PP
560 .\"O If
561 .\"O .B WNOHANG
562 .\"O was specified in
563 .\"O .I options
564 .\"O and there were no children in a waitable state, then
565 .\"O .BR waitid ()
566 .\"O returns 0 immediately and
567 .\"O the state of the
568 .\"O .I siginfo_t
569 .\"O structure pointed to by
570 .\"O .I infop
571 .\"O is unspecified.
572 .B WNOHANG
573 ¤¬
574 .I options
575 ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
576 waitable ¾õÂÖ¤Î»Ò¥×¥í¥»¥¹¤¬¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢
577 .BR waitid ()
578 ¤Ï¤¹¤°¤Ë 0 ¤òÊÖ¤¹¡£¤³¤Î¤È¤­¡¢
579 .I infop
580 ¤¬»Ø¤¹
581 .I siginfo_t
582 ¹½Â¤ÂΤÎÆâÍƤÏÉÔÄê¤Ç¤¢¤ë¡£
583 .\"O .\" POSIX.1-2001 leaves this possibility unspecified; most
584 .\"O .\" implementations (including Linux) zero out the structure
585 .\"O .\" in this case, but at at least one implementation (AIX 5.1)
586 .\"O .\" does not -- MTK Nov 04
587 .\" POSIX.1-2001 ¤Ç¤Ï¡¢ÉÔÄê¤Î²ÄǽÀ­¤ò»Ä¤·¤Æ¤¤¤ë¡£
588 .\" (Linux ¤ò´Þ¤à) ¤Û¤È¤ó¤É¤Î¼ÂÁõ¤Ç¤Ï¡¢¤³¤Î¾ì¹ç¤Ë¹½Â¤ÂΤò 0 ¤ÇËä¤á¤ë¤¬¡¢
589 .\" ¾¯¤Ê¤¯¤È¤â°ì¤Ä¤Î¼ÂÁõ (AIX 5.1) ¤Ç¤Ï¤½¤¦¤Ê¤é¤Ê¤¤¡£ -- MTK Nov 04
590 .\"O To distinguish this case from that where a child was in a
591 .\"O waitable state, zero out the
592 .\"O .I si_pid
593 .\"O field before the call and check for a nonzero value in this field
594 .\"O after the call returns.
595 ¤³¤Î¾ì¹ç¤ò waitable ¾õÂÖ¤Î»Ò¥×¥í¥»¥¹¤¬¤¢¤Ã¤¿¾ì¹ç¤È¶èÊ̤¹¤ë¤Ë¤Ï¡¢
596 .BR waitid ()
597 ¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë
598 .I si_pid
599 ¤ò 0 ¤Ë¤·¤Æ¤ª¤­¡¢¥³¡¼¥ë¤¬Éüµ¢¤·¤¿¸å¤Ç¤³¤Î¥Õ¥£¡¼¥ë¥É¤¬ 0 °Ê³°¤ÎÃͤ«¤É¤¦¤«
600 ¤ò¥Á¥§¥Ã¥¯¤¹¤ì¤Ð¤è¤¤¡£
601 .\"O .SH "RETURN VALUE"
602 .SH ÊÖ¤êÃÍ
603 .BR wait ():
604 .\"O on success, returns the process ID of the terminated child;
605 .\"O on error, \-1 is returned.
606 À®¸ù¤¹¤ë¤È¡¢½ªÎ»¤·¤¿»Ò¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ID ¤òÊÖ¤¹¡£
607 ¥¨¥é¡¼¤Î¾ì¹ç \-1 ¤òÊÖ¤¹¡£
608
609 .BR waitpid ():
610 .\"O on success, returns the process ID of the child whose state has changed;
611 .\"O if
612 .\"O .B WNOHANG
613 .\"O was specified and one or more child(ren) specified by
614 .\"O.I pid
615 .\"O exist, but have not yet changed state, then 0 is returned.
616 .\"O On error, \-1 is returned.
617 À®¸ù¤¹¤ë¤È¡¢¾õÂÖ¤¬ÊѲ½¤·¤¿»Ò¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ID ¤òÊÖ¤¹¡£
618 .B WNOHANG
619 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
620 .I pid
621 ¤Ç»Ø¼¨¤µ¤ì¤¿»Ò¥×¥í¥»¥¹¤¬°ì¤Ä°Ê¾å¸ºß¤¹¤ë¤¬¡¢¤É¤Î»Ò¥×¥í¥»¥¹¤Ç¤â
622 ¾õÂÖÊѲ½¤¬µ¯¤³¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢ 0 ¤òÊÖ¤¹¡£
623 ¥¨¥é¡¼¤Î¾ì¹ç \-1 ¤òÊÖ¤¹¡£
624
625 .BR waitid ():
626 .\"O returns 0 on success or
627 .\"O if
628 .\"O .B WNOHANG
629 .\"O was specified and no child(ren) specified by
630 .\"O .I id
631 .\"O has yet changed state;
632 .\"O on error, \-1 is returned.
633 À®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤¹¡£
634 .B WNOHANG
635 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
636 .I pid
637 ¤Ç»Ø¼¨¤µ¤ì¤¿»Ò¥×¥í¥»¥¹¤Ç¾õÂÖÊѲ½¤¬µ¯¤³¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤â
638 0 ¤òÊÖ¤¹¡£
639 ¥¨¥é¡¼¤Î¾ì¹ç \-1 ¤òÊÖ¤¹¡£
640 .\" FIXME: As reported by Vegard Nossum, if infop is NULL, then waitid()
641 .\" returns the PID of the child.  Either this is a bug, or it is intended
642 .\" behavior that needs to be documented.  See my Jan 2009 LKML mail
643 .\" "waitid() return value strangeness when infop is NULL".
644 .\"O Each of these calls sets
645 .\"O .I errno
646 .\"O to an appropriate value in the case of an error.
647 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¤¤¤º¤ì¤â
648 .I errno
649 ¤ËŬÀÚ¤ÊÃͤòÀßÄꤹ¤ë¡£
650 .\"O .SH ERRORS
651 .SH ¥¨¥é¡¼
652 .TP
653 .\"O .B ECHILD
654 .\"O (for
655 .\"O .BR wait ())
656 .B ECHILD
657 .RB ( wait ()
658 ¤Î¾ì¹ç)
659 .\"O The calling process does not have any unwaited-for children.
660 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Ë¤Ï¡¢wait ¤ò¹Ô¤Ã¤Æ¤¤¤Ê¤¤»Ò¥×¥í¥»¥¹¤Ï¤Ê¤¤¡£
661 .TP
662 .\"O .B ECHILD
663 .\"O (for
664 .\"O .BR waitpid ()
665 .\"O or
666 .\"O .BR waitid ())
667 .B ECHILD
668 .RB ( waitpid ()
669 ¤«
670 .BR waitid ()
671 ¤Î¾ì¹ç)
672 .\"O The process specified by
673 .\"O .I pid
674 .\"O .RB ( waitpid ())
675 .\"O or
676 .\"O .I idtype
677 .\"O and
678 .\"O .I id
679 .\"O .RB ( waitid ())
680 .\"O does not exist or is not a child of the calling process.
681 .\"O (This can happen for one's own child if the action for
682 .\"O .B SIGCHLD
683 .\"O is set to
684 .\"O .BR SIG_IGN .
685 .\"O See also the \fILinux Notes\fP section about threads.)
686 .I pid
687 .RB ( waitpid ())
688 ¤«
689 .I idtype
690 ¤È
691 .I id
692 .RB ( waitid ())
693 ¤Ç»ØÄꤷ¤¿¥×¥í¥»¥¹¤¬Â¸ºß¤·¤Ê¤¤¤«¡¢¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î»Ò¥×¥í¥»¥¹¤Ç¤Ê¤¤
694 .RB ( SIGCHLD
695 ¤ÎÆ°ºî¤Ë
696 .B SIG_IGN
697 ¤òÀßÄꤷ¤¿¾ì¹ç¤Ë¤Ï¡¢¼«Ê¬¼«¿È¤Î»Ò¥×¥í¥»¥¹¤Ç¤âµ¯¤³¤ê¤¦¤ë¡£
698 ¥¹¥ì¥Ã¥É¤Ë´Ø¤·¤Æ¤Ï¡ÖLinux ¤Ç¤ÎÃí°Õ¡×¤ÎÀá¤â»²¾È¤¹¤ë¤³¤È)¡£
699 .TP
700 .B EINTR
701 .\"O .B WNOHANG
702 .\"O was not set and an unblocked signal or a
703 .\"O .B SIGCHLD
704 .\"O was caught; see.
705 .\"O .BR signal (7).
706 .B WNOHANG
707 ¤¬ÀßÄꤵ¤ì¤Æ¤ª¤é¤º¡¢¶Ø»ß (block) ¤µ¤ì¤Æ¤¤¤Ê¤¤¥·¥°¥Ê¥ë¤ä
708 .B SIGCHLD
709 ¤ò¼õ¿®¤·¤¿¡£
710 .BR signal (7)
711 »²¾È¡£
712 .TP
713 .B EINVAL
714 .\"O The
715 .\"O .I options
716 .\"O argument was invalid.
717 .I options
718 °ú¤­¿ô¤¬ÉÔÀµ¤Ç¤¢¤ë¡£
719 .\"O .SH "CONFORMING TO"
720 .SH ½àµò
721 SVr4, 4.3BSD, POSIX.1-2001.
722 .\"O .SH NOTES
723 .SH Ãí°Õ
724 .\"O A child that terminates, but has not been waited for becomes a "zombie".
725 .\"O The kernel maintains a minimal set of information about the zombie
726 .\"O process (PID, termination status, resource usage information)
727 .\"O in order to allow the parent to later perform a wait to obtain
728 .\"O information about the child.
729 .\"O As long as a zombie is not removed from the system via a wait,
730 .\"O it will consume a slot in the kernel process table, and if
731 .\"O this table fills, it will not be possible to create further processes.
732 .\"O If a parent process terminates, then its "zombie" children (if any)
733 .\"O are adopted by
734 .\"O .BR init (8),
735 .\"O which automatically performs a wait to remove the zombies.
736 ½ªÎ»¤·¤¿¤¬¡¢wait ¤µ¤ì¤Æ¤¤¤Ê¤¤»Ò¥×¥í¥»¥¹¤Ï¡Ö¥¾¥ó¥Ó¡×¤Ë¤Ê¤ë¡£
737 ¸å¤Ç¿Æ¥×¥í¥»¥¹¤¬ wait ¤ò¼Â¹Ô¤·¤Æ»Ò¥×¥í¥»¥¹¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤ò¼èÆÀ¤Ç¤­¤ë¤è¤¦¤Ë¡¢
738 ¥«¡¼¥Í¥ë¤Ï¥¾¥ó¥Ó¥×¥í¥»¥¹¤Ë¤Ä¤¤¤ÆºÇ¾®¸Â¤Î¾ðÊó (PID¡¢½ªÎ»¥¹¥Æ¡¼¥¿¥¹¡¢
739 ¥ê¥½¡¼¥¹»ÈÍѾõ¶·) ¤òÊÝ»ý¤¹¤ë¡£
740 ¥¾¥ó¥Ó¥×¥í¥»¥¹¤Ï¡¢ wait ¤Ë¤è¤Ã¤Æ¥·¥¹¥Æ¥à¤«¤éºï½ü¤µ¤ì¤Ê¤¤¸Â¤ê¡¢
741 ¥«¡¼¥Í¥ë¤Î¥×¥í¥»¥¹¥Æ¡¼¥Ö¥ë¤Î 1 ¥¨¥ó¥È¥ê¤ò¾ÃÈñ¤¹¤ë¡£¤³¤Î¥×¥í¥»¥¹¥Æ¡¼¥Ö¥ë¤¬
742 °ìÇդˤʤë¤È¡¢¿·¤¿¤Ë¥×¥í¥»¥¹¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¯¤Ê¤ë¡£
743 ¿Æ¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ë¤È¡¢¤½¤Î¿Æ¥×¥í¥»¥¹¤Î¡Ö¥¾¥ó¥Ó¡×¤Î
744 »Ò¥×¥í¥»¥¹¤Ï (¤â¤·¤¢¤ì¤Ð)
745 .BR init (8)
746 ¤ÎÍܻҤȤʤ롣
747 .BR init (8)
748 ¤Ï wait ¤ò¼«Æ°Åª¤Ë¼Â¹Ô¤·¡¢¥¾¥ó¥Ó¤òºï½ü¤¹¤ë¡£
749
750 .\"O POSIX.1-2001 specifies that if the disposition of
751 .\"O .B SIGCHLD
752 .\"O is set to
753 .\"O .B SIG_IGN
754 .\"O or the
755 .\"O .B SA_NOCLDWAIT
756 .\"O flag is set for
757 .\"O .B SIGCHLD
758 .\"O (see
759 .\"O .BR sigaction (2)),
760 .\"O then children that terminate do not become zombies and a call to
761 .\"O .BR wait ()
762 .\"O or
763 .\"O .BR waitpid ()
764 .\"O will block until all children have terminated, and then fail with
765 .\"O .I errno
766 .\"O set to
767 .\"O .BR ECHILD .
768 POSIX.1-2001 ¤Ç¤Ï°Ê²¼¤Î¤è¤¦¤Ëµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
769 .B SIGCHLD
770 ¤ÎÆ°ºî¤¬
771 .B SIG_IGN
772 ¤ËÀßÄꤵ¤ì¤¿¤«¡¢
773 .B SIGCHLD
774 ¤ËÂФ·¤Æ
775 .B SA_NOCLDWAIT
776 ¥Õ¥é¥°¤¬ÀßÄꤵ¤ì¤¿¾ì¹ç
777 .RB ( sigaction (2)
778 »²¾È)¡¢½ªÎ»¤·¤¿»Ò¥×¥í¥»¥¹¤Ï¥¾¥ó¥Ó¤Ë¤Ï¤Ê¤é¤º¡¢
779 .BR wait ()
780 ¤ä
781 .BR waitpid ()
782 ¤Î¸Æ¤Ó½Ð¤·¤ÏÁ´¤Æ¤Î»Ò¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ë¤Þ¤ÇÄä»ß¤·¡¢
783 »Ò¥×¥í¥»¥¹¤¬Á´Éô½ªÎ»¤·¤¿¸å
784 .I errno
785 ¤Ë
786 .B ECHILD
787 ¤òÀßÄꤷ¤Æ¼ºÇÔ¤¹¤ë¡£
788 .\"O (The original POSIX standard left the behavior of setting
789 .\"O .B SIGCHLD
790 .\"O to
791 .\"O .B SIG_IGN
792 .\"O unspecified.
793 .\"O Note that even though the default disposition of
794 .\"O .B SIGCHLD
795 .\"O is "ignore", explicitly setting the disposition to
796 .\"O .B SIG_IGN
797 .\"O results in different treatment of zombie process children.)
798 (¤â¤È¤â¤È¤Î POSIX É¸½à¤Ï
799 .B SIGCHLD
800 ¤Ë
801 .B SIG_IGN
802 ¤òÀßÄꤷ¤¿¾ì¹ç¤Î¿¶¤ëÉñ¤¤¤ò̤µ¬Äê¤Î¤Þ¤Þ¤Ë¤·¤Æ¤¤¤ë¡£
803 .B SIGCHLD
804 ¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤¬¡Ö̵»ë¡×¤Ç¤¢¤ë¤Ë¤â¤«¤«¤ï¤é¤º¡¢
805 .B SIGCHLD
806 ¤ÎÆ°ºî¤È¤·¤Æ
807 .B SIG_IGN
808 ¤òÌÀ¼¨Åª¤ËÀßÄꤷ¤¿¾ì¹ç¤Ë¤Ï¥¾¥ó¥Ó¥×¥í¥»¥¹¤Î»Ò¥×¥í¥»¥¹¤Î°·¤¤¤¬
809 °Û¤Ê¤ëÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£)
810 .\"O Linux 2.6 conforms to this specification.
811 .\"O However, Linux 2.4 (and earlier) does not:
812 Linux 2.6 ¤Ï¤³¤Î»ÅÍͤ˽àµò¤·¤Æ¤¤¤ë¡£
813 ¤·¤«¤·¡¢Linux 2.4 (¤È¤½¤ì°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó) ¤Ï¤½¤¦¤Ç¤Ï¤Ê¤¤:
814 .\"O if a
815 .\"O .BR wait ()
816 .\"O or
817 .\"O .BR waitpid ()
818 .\"O call is made while
819 .\"O .B SIGCHLD
820 .\"O is being ignored, the call behaves just as though
821 .\"O .B SIGCHLD
822 .\"O were not being ignored, that is, the call blocks until the next child
823 .\"O terminates and then returns the process ID and status of that child.
824 .B SIGCHLD
825 ¤¬Ìµ»ë¤µ¤ì¤ë¾õÂÖ¤Ç
826 .BR wait ()
827 ¤Þ¤¿¤Ï
828 .BR waitpid ()
829 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¾ì¹ç¡¢
830 .B SIGCHLD
831 ¤¬Ìµ»ë¤µ¤ì¤Æ¤¤¤Ê¤¤¤«¤Î¤è¤¦¤Ë¿¶¤ëÉñ¤¦¡£
832 ¤Ä¤Þ¤ê¡¢¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤Æ¼¡¤Î»Ò¥×¥í¥»¥¹¤Î½ªÎ»¤Þ¤Ç¥Ö¥í¥Ã¥¯¤µ¤ì¡¢
833 ½ªÎ»¤·¤¿»Ò¥×¥í¥»¥¹¤Î PID ¤È¾õÂÖ¤¬ÊÖ¤µ¤ì¤ë¡£
834 .\"O .SS Linux Notes
835 .SS Linux ¤Ç¤ÎÃí°Õ
836 .\"O In the Linux kernel, a kernel-scheduled thread is not a distinct
837 .\"O construct from a process.
838 .\"O Instead, a thread is simply a process
839 .\"O that is created using the Linux-unique
840 .\"O .BR clone (2)
841 .\"O system call; other routines such as the portable
842 .\"O .BR pthread_create (3)
843 .\"O call are implemented using
844 .\"O .BR clone (2);
845 .\"O they cannot be used with
846 .\"O .BR waitid ():
847 Linux ¥«¡¼¥Í¥ë¤Ç¤Ï¡¢¥«¡¼¥Í¥ë¤Ë¤è¤Ã¤Æ¥¹¥±¥¸¥å¡¼¥ë¤µ¤ì¤ë¥¹¥ì¥Ã¥É¤Ï
848 ¥×¥í¥»¥¹¤ÈÌÀ³Î¤Ë¶èÊ̤Ǥ­¤ë¹½À®Í×ÁǤǤϤʤ¤¡£¥¹¥ì¥Ã¥É¤Ï Linux ¸ÇÍ­¤Î
849 .BR clone (2)
850 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»ÈÍѤ·¤ÆÀ¸À®¤µ¤ì¤ë¥×¥í¥»¥¹¤Ë²á¤®¤Ê¤¤¡£
851 °Ü¿¢À­¤Î¤¢¤ë
852 .BR pthread_create (3)
853 ¥³¡¼¥ë¤Î¤è¤¦¤Ê¾¤Î¥ë¡¼¥Á¥ó¤Ï
854 .BR clone (2)
855 ¤ò»ÈÍѤ·¤Æ¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë;
856 ¤³¤ì¤é¤Ç¤Ï
857 .BR waitid ()
858 ¤ò»È¤¦¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
859 .\"O Before Linux 2.4, a thread was just a special case of a process,
860 .\"O and as a consequence one thread could not wait on the children
861 .\"O of another thread, even when the latter belongs to the same thread group.
862 Linux 2.4 ¤è¤êÁ°¤Ç¤Ï¡¢¥¹¥ì¥Ã¥É¤Ïñ¤ËÆüì¤Ê¥×¥í¥»¥¹¤Ç¤¢¤Ã¤¿¤Î¤Ç¡¢
863 Î㤨Ʊ¤¸¥¹¥ì¥Ã¥É¥°¥ë¡¼¥×¤Ç¤¢¤Ã¤Æ¤â¡¢
864 ¤¢¤ë¥¹¥ì¥Ã¥É¤¬Ê̤Υ¹¥ì¥Ã¥É¤Î»Ò¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ë¤Î¤òÂԤĤ³¤È¤Ï½ÐÍè¤Ê¤«¤Ã¤¿¡£
865 .\"O However, POSIX prescribes such functionality, and since Linux 2.4
866 .\"O a thread can, and by default will, wait on children of other threads
867 .\"O in the same thread group.
868 ¤·¤«¤·¡¢POSIX ¤Ç¤Ï¤³¤Î¤è¤¦¤Êµ¡Ç½¤òµ¬Äꤷ¤Æ¤ª¤ê¡¢
869 Linux 2.4 °Ê¹ß¤Ç¤Ï¡¢¤¢¤ë¥¹¥ì¥Ã¥É¤¬Æ±¤¸¥¹¥ì¥Ã¥É¥°¥ë¡¼¥×¤Î¾¤Î¥¹¥ì¥Ã¥É¤Î
870 »Ò¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ë¤Î¤òÂԤĤ³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£
871 ¤½¤·¤Æ¾­Íè¤Ï¤³¤ì¤¬¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤Ë¤Ê¤ë¤Ç¤¢¤í¤¦¡£
872 .LP
873 .\"O The following Linux-specific
874 .\"O .I options
875 .\"O are for use with children created using
876 .\"O .BR clone (2).
877 .BR clone (2)
878 ¤òÍѤ¤¤Æºî¤é¤ì¤¿»Ò¥×¥í¥»¥¹¤Ë¤Ï¡¢°Ê²¼¤Î Linux ¸ÇÍ­¤Î
879 .I options
880 ¤¬»ÈÍѤǤ­¤ë¡£
881 .TP
882 .B __WCLONE
883 .\" since 0.99pl10
884 .\"O Wait for "clone" children only.
885 .\"O If omitted then wait
886 .\"O for "non-clone" children only.
887 .\"O (A "clone" child is one
888 .\"O which delivers no signal, or a signal other than
889 .\"O .B SIGCHLD
890 .\"O to its parent upon termination.)
891 "clone" ¤Ê»Ò¥×¥í¥»¥¹¤À¤±¤òÂԤġ£
892 »ØÄꤵ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤ÏÈó "clone" ¤Ê»Ò¥×¥í¥»¥¹¤À¤±¤òÂÔ¤Ä
893 ("clone" ¤Ê»Ò¥×¥í¥»¥¹¤Ï¡¢½ªÎ»»þ¤Ë¿Æ¥×¥í¥»¥¹¤ØÁ´¤¯¥·¥°¥Ê¥ë¤òÁ÷¤é¤Ê¤¤¤«¡¢
894 .B SIGCHLD
895 °Ê³°¤Î¥·¥°¥Ê¥ë¤òÁ÷¤ë)¡£
896 .\"O This option is ignored if
897 .\"O .B __WALL
898 .\"O is also specified.
899 ¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï
900 .B __WALL
901 ¤â»ØÄꤵ¤ì¤¿¾ì¹ç¤Ï̵»ë¤µ¤ì¤ë¡£
902 .TP
903 .\"O .BR __WALL " (since Linux 2.4)"
904 .BR __WALL " (Linux 2.4 °Ê¹ß)"
905 .\" since patch-2.3.48
906 .\"O Wait for all children, regardless of
907 .\"O type ("clone" or "non-clone").
908 "clone" ¤Ç¤¢¤ë¤«¤Ê¤¤¤«¤Ë´Ø¤ï¤é¤º¡¢
909 Á´¤Æ¤Î»Ò¥×¥í¥»¥¹¤òÂԤġ£
910 .TP
911 .\"O .BR __WNOTHREAD " (since Linux 2.4)"
912 .BR __WNOTHREAD " (Linux 2.4 °Ê¹ß)"
913 .\" since patch-2.4.0-test8
914 .\"O Do not wait for children of other threads in
915 .\"O the same thread group.
916 .\"O This was the default before Linux 2.4.
917 Ʊ¤¸¥¹¥ì¥Ã¥É¥°¥ë¡¼¥×¤Î¾¤Î¥¹¥ì¥Ã¥É¤Î»Ò¥×¥í¥»¥¹¤ÏÂÔ¤¿¤Ê¤¤¡£
918 Linux 2.4 ¤è¤êÁ°¤Ç¤Ï¥Ç¥Õ¥©¥ë¥È¤Ç¤¢¤Ã¤¿¡£
919 .\"O .SH EXAMPLE
920 .SH Îã
921 .\"O .\" fork.2 refers to this example program.
922 .\" fork.2 ¤â¤³¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò»²¾È¤·¤Æ¤¤¤ë¡£
923 .\"O The following program demonstrates the use of
924 .\"O .BR fork (2)
925 .\"O and
926 .\"O .BR waitpid ().
927 .\"O The program creates a child process.
928 .\"O If no command-line argument is supplied to the program,
929 .\"O then the child suspends its execution using
930 .\"O .BR pause (2),
931 .\"O to allow the user to send signals to the child.
932 .\"O Otherwise, if a command-line argument is supplied,
933 .\"O then the child exits immediately,
934 .\"O using the integer supplied on the command line as the exit status.
935 .\"O The parent process executes a loop that monitors the child using
936 .\"O .BR waitpid (),
937 .\"O and uses the W*() macros described above to analyze the wait status value.
938 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢
939 .BR fork (2)
940 ¤È
941 .BR waitpid ()
942 ¤Î»ÈÍÑÊýË¡¤ÎÎã¤ò¼¨¤·¤Æ¤¤¤ë¡£
943 ¤³¤Î¥×¥í¥°¥é¥à¤Ç¤Ï»Ò¥×¥í¥»¥¹¤òÀ¸À®¤¹¤ë¡£
944 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤¬»ØÄꤵ¤ì¤Ê¤«¤Ã¤¿¤È¤­¤Ï¡¢
945 »Ò¥×¥í¥»¥¹¤Ï
946 .BR pause (2)
947 ¤ò»È¤Ã¤Æ¤½¤Î¼Â¹Ô¤ò°ì»þÄä»ß¤·¡¢¥æ¡¼¥¶¤¬¤½¤Î»Ò¥×¥í¥»¥¹¤Ë
948 ¥·¥°¥Ê¥ë¤òÁ÷¿®¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¡£
949 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢
950 »Ò¥×¥í¥»¥¹¤Ïľ¤Á¤Ë½ªÎ»¤·¡¢
951 ¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ç»ØÄꤵ¤ì¤¿À°¿ô¤ò½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤È¤·¤Æ»ÈÍѤ¹¤ë¡£
952 ¿Æ¥×¥í¥»¥¹¤Ï¡¢
953 .BR waitpid ()
954 ¤ò»È¤Ã¤Æ»Ò¥×¥í¥»¥¹¤ò´Æ»ë¤·¡¢
955 wait ¤Î¥¹¥Æ¡¼¥¿¥¹Ãͤò¾åµ­¤Î W*() ¥Þ¥¯¥í¤ò»È¤Ã¤Æ²òÀϤ¹¤ë¤È¤¤¤¦
956 ¥ë¡¼¥×¤ò¼Â¹Ô¤¹¤ë¡£
957
958 .\"O The following shell session demonstrates the use of the program:
959 ²¼µ­¤Î¤Î¥·¥§¥ë¡¦¥»¥Ã¥·¥ç¥ó¤Ï¥×¥í¥°¥é¥à¤Î¼Â¹ÔÎã¤Ç¤¢¤ë:
960 .in +4n
961 .nf
962
963 .RB "$" " ./a.out &"
964 Child PID is 32360
965 [1] 32359
966 .RB "$" " kill \-STOP 32360"
967 stopped by signal 19
968 .RB "$" " kill \-CONT 32360"
969 continued
970 .RB "$" " kill \-TERM 32360"
971 killed by signal 15
972 [1]+  Done                    ./a.out
973 $
974 .fi
975 .in
976 .\"O .SS Program source
977 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
978 \&
979 .nf
980 #include <sys/wait.h>
981 #include <stdlib.h>
982 #include <unistd.h>
983 #include <stdio.h>
984
985 int
986 main(int argc, char *argv[])
987 {
988     pid_t cpid, w;
989     int status;
990
991     cpid = fork();
992     if (cpid == \-1) {
993         perror("fork");
994         exit(EXIT_FAILURE);
995     }
996
997     if (cpid == 0) {            /* Code executed by child */
998         printf("Child PID is %ld\\n", (long) getpid());
999         if (argc == 1)
1000             pause();                    /* Wait for signals */
1001         _exit(atoi(argv[1]));
1002
1003     } else {                    /* Code executed by parent */
1004         do {
1005             w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
1006             if (w == \-1) {
1007                 perror("waitpid");
1008                 exit(EXIT_FAILURE);
1009             }
1010
1011             if (WIFEXITED(status)) {
1012                 printf("exited, status=%d\\n", WEXITSTATUS(status));
1013             } else if (WIFSIGNALED(status)) {
1014                 printf("killed by signal %d\\n", WTERMSIG(status));
1015             } else if (WIFSTOPPED(status)) {
1016                 printf("stopped by signal %d\\n", WSTOPSIG(status));
1017             } else if (WIFCONTINUED(status)) {
1018                 printf("continued\\n");
1019             }
1020         } while (!WIFEXITED(status) && !WIFSIGNALED(status));
1021         exit(EXIT_SUCCESS);
1022     }
1023 }
1024 .fi
1025 .\"O .SH "SEE ALSO"
1026 .SH ´ØÏ¢¹àÌÜ
1027 .BR _exit (2),
1028 .BR clone (2),
1029 .BR fork (2),
1030 .BR kill (2),
1031 .BR ptrace (2),
1032 .BR sigaction (2),
1033 .BR signal (2),
1034 .BR wait4 (2),
1035 .BR pthread_create (3),
1036 .BR credentials (7),
1037 .BR signal (7)