File: wait.2

package info (click to toggle)
manpages-ja 0.5.0.0.20080615-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 20,508 kB
  • ctags: 1
  • sloc: sh: 13,690; perl: 157; makefile: 114
file content (633 lines) | stat: -rw-r--r-- 17,261 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (c) 1993 by Thomas Koenig <ig25@rz.uni-karlsruhe.de>
.\" and Copyright (c) 2004 by Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" License.
.\"
.\" Modified Sat Jul 24 13:30:06 1993 by Rik Faith <faith@cs.unc.edu>
.\" Modified Sun Aug 21 17:42:42 1994 by Rik Faith <faith@cs.unc.edu>
.\"          (Thanks to Koen Holtman <koen@win.tue.nl>)
.\" Modified Wed May 17 15:54:12 1995 by Rik Faith <faith@cs.unc.edu>
.\"           To remove *'s from status in macros (Thanks to Michael Shields).
.\" Modified as suggested by Nick Duffek <nsd@bbc.com>, aeb, 960426
.\" Modified Mon Jun 23 14:09:52 1997 by aeb - add EINTR.
.\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff.
.\" Modified Mon Jul 24 21:37:38 2000 by David A. Wheeler
.\"          <dwheeler@dwheeler.com> - noted thread issues.
.\" Modified 26 Jun 01 by Michael Kerrisk
.\"          Added __WCLONE, __WALL, and __WNOTHREAD descriptions
.\" Modified 2001-09-25, aeb
.\" Modified 26 Jun 01 by Michael Kerrisk, <mtk.manpages@gmail.com>
.\"	Updated notes on setting disposition of SIGCHLD to SIG_IGN
.\" 2004-11-11, mtk
.\"	Added waitid(2); added WCONTINUED and WIFCONTINUED()
.\"	Added text on SA_NOCLDSTOP
.\"	Updated discussion of SA_NOCLDWAIT to reflect 2.6 behavior
.\"	Much other text rewritten
.\" 2005-05-10, mtk, __W* flags can't be used with waitid()
.\"
.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya all rights reserved.
.\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved.
.\" Translated 1997-03-04, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Modified 2000-09-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated 2001-06-25, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2001-10-15, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2002-10-21, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2003-01-27, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2003-09-12, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2005-03-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2005-12-26, Akihiro MOTOKI
.\"
.\"WORD:	signal handling		ʥ
.\"WORD:	suspend			(suspend)
.\"WORD:	zombie			(zombie)
.\"WORD:	child process		ҥץ
.\"WORD:	process group		ץ롼
.\"WORD:	process group ID	ץ롼ID
.\"WORD:	stop			(stop)
.\"WORD:	effective user ID	¸桼ID
.\"WORD:	block			ػ(block)
.\"
.TH WAIT 2  2007-07-26 "Linux" "Linux Programmer's Manual"
.SH ̾
wait, waitpid, waitid \- ץξѲԤ
.SH 
.B #include <sys/types.h>
.br
.B #include <sys/wait.h>
.sp
.BI "pid_t wait(int *" "status" );

.BI "pid_t waitpid(pid_t " pid ", int *" status ", int " options );

.BI "int waitid(idtype_t " idtype ", id_t " id \
", siginfo_t *" infop ", int " options );
.sp
.in -4n
glibc εǽޥ׷
.RB ( feature_test_macros (7)
):
.in
.sp
.BR waitid ():
_SVID_SOURCE || _XOPEN_SOURCE
.SH 
ΥƥॳϤ⡢ƤӽФץλҥץ
ѲԤ֤ѲλҥץξΤ
Ѥ롣
ѲȤϰʲΤ줫Ǥ:
ҥץνλʥˤҥץߡ
ʥˤҥץκƳ
ҥץλϡwait ¹Ԥ뤳Ȥǡ
ƥबλҥץ˴Ϣ꥽Ǥ褦ˤʤ롣
wait ¹Ԥʤäˤϡλҥץ
֥ӡ׾֤ǻĤ³ (դξϤ򻲾ȤΤ)

ҥץξѲǤȯƤ硢Υ
롣ʳξϡҥץξѲ뤫
ʥϥɥˤꥷƥॳ뤬Ǥޤǡ
 (block)  (Ԥϡ
.BR sigaction (2)

.B SA_RESTART
ե饰ˤꥷƥॳ뤬ưŪ˺ƥȤ褦ˤʤäƤʤ
ưǤ)
ʲǤϡѲäΥƥॳΤ줫
äԤƤʤҥץ
.I waitable
(Ԥǽ) ȸƤ֡
.SS "wait()  waitpid()"
.BR wait ()
ƥॳϡҥץΤ줫λޤ
ƤӽФΥץμ¹Ԥߤ롣
ʲĤθƤӽФǤ:
.nf

    wait(&status);

    waitpid(\-1, &status, 0);
.fi

.BR waitpid ()
ƥॳϡ
.I pid
ǻꤷҥץξѲޤǡ
ƤӽФΥץμ¹Ԥߤ롣ǥեȤǤϡ
.BR waitpid ()
ϻҥץνλԤĤư
.I options
ˤѹǽǤ롣

.I pid
˻Ǥͤϰʲ̤:
.IP "< \-1"
ץ롼ID 
.I pid
ͤҥץΤ줫λޤǤԤġ
.IP \-1
ҥץΤɤ줫λޤԤġ
.IP 0
ץ롼ID ƤӽФץΤΤ
ҥץԤġ
.IP "> 0"
ץID 
.I pid
ҥץԤġ
.PP
.I options
ͤϼ 0 İʾ¤Ǥ:
.TP 12
.B WNOHANG
Ѳäҥץʤˤ롣
.TP
.B WUNTRACED
ҥץߤˤ (ҥץ
.BR ptrace (2)
ǥȥ졼ƤϽ)
Υץ󤬻ꤵƤʤǤ⡢ߤץ
֥ȥ졼 (traced)פƤСҥץξ֤𤵤롣
.TP
.B WCONTINUED
(Linux 2.6.10 ʹ)
ߤҥץ
.B SIGCONT
ˤƳˤ롣
.PP
(Linux ѥץˤĤƤϸҤ)
.PP
.B WUNTRACED

.B WCONTINUED
ξץͭȤʤΤϡ
.B SIGCHLD
ʥФ
.B SA_NOCLDSTOP
ե饰ꤵƤʤǤ
.RB ( sigaction (2)
򻲾)
.PP
.I status
 NULL ǤʤС
.BR wait ()

.BR waitpid ()

.I status
ǻؤ \fIint\fP ˾־Ǽ롣
ϰʲΥޥȤäƸǤ롣
(Υޥΰˤϡ
.BR wait ()

.BR waitpid ()
񤭹ΤΤꤹ롣ݥ󥿤ǤϤʤ!)
.TP
.BI WIFEXITED( status )
ҥץ˽λ˿֤
ˡפȤϡ
.BR exit (3)

.BR _exit (2)
ƤӽФ줿硢⤷
main() Ǥ롣
.TP
.BI WEXITSTATUS( status )
ҥץνλơ֤
λơ
.I status
β 8ӥåȤǹƤꡢ
.BR exit (3)

.BR _exit (2)
θƤӽФϤ줿͡⤷ main()  return ʸ
Ȥƻꤵ줿ͤǤ롣
ΥޥѤΤ
.B WIFEXITED
֤ˤ٤Ǥ롣
.TP
.BI WIFSIGNALED( status )
ҥץʥˤ꽪λ˿֤
.TP
.BI WTERMSIG( status )
ҥץλθȤʤäʥֹ֤
ΥޥѤΤ
.B WIFSIGNALED
֤ˤ٤Ǥ롣
.TP
.BI WCOREDUMP( status )
ҥץפ˿֤
ΥޥѤΤ
.B WIFSIGNALED
֤ˤ٤Ǥ롣
Υޥ POSIX.1-2001 ǤϵꤵƤ餺
(AIX, SunOS ʤɤ) Ĥ Unix μǤѤǤʤ
ɬ #ifdef WCOREDUMP ... #endif dzäƻѤ뤳ȡ
.TP
.BI WIFSTOPPED( status )
ҥץʥˤߤ˿֤
줬ˤʤΤϡƥॳ뤬
.B WUNTRACED
ꤷƸƤӽФ줿礫ҥץȥ졼Ƥ
.RB ( ptrace (2)
) Ǥ롣
.TP
.BI WSTOPSIG( status )
ҥץߤʥֹ֤
ΥޥѤΤ
.B WIFSTOPPED
 0 ʳ֤ˤ٤Ǥ롣
.TP
.BI WIFCONTINUED( status )
(Linux 2.6.10 ʹ)
ҥץ
.B SIGCONT
ˤƳ˿֤
.SS "waitid()"
.BR waitid ()
ƥॳ (Linux 2.6.9 ʹߤѲǽ) Ȥȡ
ҥץΤɤξѲԤĤˤĤƤ٤椬Ǥ롣


.I idtype

.I id
ǤɤλҥץԤĤ򤹤:
.IP "\fIidtype\fP == \fBP_PID\fP"
ץID 
.I id
ȰפҥץԤġ
.IP "\fIidtype\fP == \fBP_PGID\fP"
ץ롼ID 
.I id
ȰפҥץԤġ
.IP "\fIidtype\fP == \fBP_ALL\fP"
ҥץоݤԤġ
.I id
̵뤵롣
.PP
ҥץΤɤξѲԤĤϰʲΥե饰ǻꤹ
.RI ( options
ˤ 1İʾΥե饰¤Ȥäƻꤹ):
.TP 12
.B WEXITED
ҥץνλԤġ
.TP
.B WSTOPPED
ҥץʥˤߤΤԤġ
.TP
.B WCONTINUED
(ߤƤ) ҥץ
.B SIGCONT
ƺƳΤԤġ
.PP
˰ʲΥե饰¤η
.I options
˻Ǥ:
.TP 12
.B WNOHANG
.BR waitpid ()
Ʊ͡
.TP
.B WNOWAIT
waitable ֤Υץ򤽤Τޤޤˤ롣θ wait 
ȤäơƱҥץξ־⤦ټ뤳ȤǤ롣
.PP
ˤϡ
.BR waitid ()

.I infop
ؤ
.I siginfo_t
¤ΤΰʲΥեɤꤹ:
.TP 12
\fIsi_pid\fP
ҥץΥץID
.TP
\fIsi_uid\fP
ҥץμ¥桼ID
(Υեɤ¾ΤۤȤɤμǤꤵʤ)
.TP
\fIsi_signo\fP

.B SIGCHLD
ꤵ롣
.TP
\fIsi_status\fP
.BR _exit (2)
(
.BR exit (3))
˻ꤵ줿ҥץνλơ⤷
ҥץνλߡƳθȤʤäʥ뤬ꤵ롣
Υեɤɤ᤹뤫ϡ
.I si_code
եɤ򻲾ȤƷ뤳ȤǤ롣
.TP
\fIsi_code\fP
ʲΤ줫ꤵ:
.B CLD_EXITED
(ҥץ
.BR _exit (2)
ƤӽФ);
.B CLD_KILLED
(ʥˤҥץ kill 줿);
.B CLD_STOPPED
(ʥˤҥץߤ);
.B CLD_CONTINUED
.RB ( SIGCONT
ˤҥץƳ줿)
.PP
.B WNOHANG

.I options
˻ꤵƤơ
waitable ֤λҥץʤäˤϡ
.BR waitid ()
Ϥ 0 ֤ΤȤ
.I infop
ؤ
.I siginfo_t
¤ΤƤǤ롣
.\" POSIX.1-2001 ǤϡβǽĤƤ롣
.\" (Linux ޤ) ۤȤɤμǤϡξ˹¤Τ 0 뤬
.\" ʤȤĤμ (AIX 5.1) ǤϤʤʤ -- MTK Nov 04
ξ waitable ֤λҥץäȶ̤ˤϡ
.BR waitid ()
ƤӽФ
.I si_pid
 0 ˤƤ뤬ǤΥեɤ 0 ʳͤɤ
åФ褤
.SH ֤
.BR wait ():
ȡλҥץΥץID ֤
顼ξ \-1 ֤

.BR waitpid ():
ȡ֤ѲҥץΥץID ֤
.B WNOHANG
ꤵƤơ
.I pid
ǻؼ줿ҥץİʾ¸ߤ뤬ɤλҥץǤ
ѲäƤʤäϡ 0 ֤
顼ξ \-1 ֤

.BR waitid ():
 0 ֤
.B WNOHANG
ꤵƤơ
.I pid
ǻؼ줿ҥץǾѲäƤʤäˤ
0 ֤
顼ξ \-1 ֤

顼ξ硢ΥƥॳϤ
.I errno
Ŭڤͤꤹ롣
.SH 顼
.TP
.B ECHILD
.RB ( wait ()
ξ)
ƤӽФץˤϡwait ԤäƤʤҥץϤʤ
.TP
.B ECHILD
.RB ( waitpid ()

.BR waitid ()
ξ)
.I pid
.RB ( waitpid ())

.I idtype

.I id
.RB ( waitid ())
ǻꤷץ¸ߤʤƤӽФץλҥץǤʤ
.RB ( SIGCHLD
ư
.B SIG_IGN
ꤷˤϡʬȤλҥץǤⵯꤦ롣
åɤ˴ؤƤϡLinux Ǥաפ⻲Ȥ뤳)
.TP
.B EINTR
.B WNOHANG
ꤵƤ餺ػ (block) Ƥʤʥ
.B SIGCHLD

.TP
.B EINVAL
.I options
Ǥ롣
.SH 
SVr4, 4.3BSD, POSIX.1-2001.
.SH 
λwait Ƥʤҥץϡ֥ӡפˤʤ롣
ǿƥץ wait ¹ԤƻҥץˤĤƤξǤ褦ˡ
ͥϥӥץˤĤƺǾ¤ξ (PIDλơ
꥽Ѿ) ݻ롣
ӥץϡ wait ˤäƥƥफʤ¤ꡢ
ͥΥץơ֥ 1 ȥ񤹤롣Υץơ֥뤬
դˤʤȡ˥ץ뤳ȤǤʤʤ롣
ƥץλȡοƥץΡ֥ӡפ
ҥץ (⤷)
.BR init (8)
ܻҤȤʤ롣
.BR init (8)
 wait ưŪ˼¹ԤӤ롣

POSIX.1-2001 ǤϰʲΤ褦˵ꤵƤ롣
.B SIGCHLD
ư
.B SIG_IGN
ꤵ줿
.B SIGCHLD
Ф
.B SA_NOCLDWAIT
ե饰ꤵ줿
.RB ( sigaction (2)
)λҥץϥӤˤϤʤ餺
.BR wait ()

.BR waitpid ()
θƤӽФƤλҥץλޤߤ
ҥץλ
.I errno

.B ECHILD
ꤷƼԤ롣
(ȤȤ POSIX ɸ
.B SIGCHLD

.B SIG_IGN
ꤷο񤤤̤ΤޤޤˤƤ롣)
Linux 2.6 Ϥλͤ˽򤷤Ƥ롣
Linux 2.4 (ȤΥС) ϤǤϤʤ:
.B SIGCHLD
̵뤵֤
.BR wait ()
ޤ
.BR waitpid ()
ƤӽФ줿硢
.B SIGCHLD
̵뤵ƤʤΤ褦˿񤦡
ĤޤꡢƤӽФˤäƼλҥץνλޤǥ֥å졢
λҥץ PID Ⱦ֤֤롣
.SS Linux Ǥ
Linux ͥǤϡͥˤäƥ塼뤵륹åɤ
ץΤ˶̤Ǥ빽ǤǤϤʤåɤ Linux ͭ
.BR clone (2)
ƥॳѤץ˲᤮ʤ
ܿΤ
.BR pthread_create (3)
Τ褦¾Υ롼
.BR clone (2)
ѤƼƤ;
Ǥ
.BR waitid ()
ȤȤϤǤʤ
Linux 2.4 ǤϡåɤñüʥץǤäΤǡ
㤨Ʊåɥ롼פǤäƤ⡢
륹åɤ̤ΥåɤλҥץλΤԤĤȤϽʤä
POSIX ǤϤΤ褦ʵǽꤷƤꡢ
Linux 2.4 ʹߤǤϡ륹åɤƱåɥ롼פ¾Υåɤ
ҥץλΤԤĤȤǤ褦ˤʤä
ƾϤ줬ǥեȤưˤʤǤ
.LP
.BR clone (2)
Ѥƺ줿ҥץˤϡʲ Linux ͭ
.I options
ѤǤ롣
.TP
.B __WCLONE
.\" since 0.99pl10
"clone" ʻҥץԤġ
ꤵʤä "clone" ʻҥץԤ
("clone" ʻҥץϡλ˿ƥץʥʤ
.B SIGCHLD
ʳΥʥ)
Υץ
.B __WALL
ꤵ줿̵뤵롣
.TP
.B __WALL
.\" since patch-2.3.48
(Linux 2.4 ʹ) "clone" Ǥ뤫ʤ˴ؤ餺
ƤλҥץԤġ
.TP
.B __WNOTHREAD
.\" since patch-2.4.0-test8
(Linux 2.4 ʹ) Ʊåɥ롼פ¾ΥåɤλҥץԤʤ
Linux 2.4 ǤϥǥեȤǤä
.SH 
.\" fork.2 ⤳Υץץ򻲾ȤƤ롣
ʲΥץϡ
.BR fork (2)

.BR waitpid ()
λˡ򼨤Ƥ롣
ΥץǤϻҥץ롣
ޥɥ饤ꤵʤäȤϡ
ҥץ
.BR pause (2)
ȤäƤμ¹Ԥߤ桼λҥץ
ʥǤ褦ˤ롣
ޥɥ饤ꤵ줿ϡ
ҥץľ˽λ
ޥɥ饤ǻꤵ줿λơȤƻѤ롣
ƥץϡ
.BR waitpid ()
Ȥäƻҥץƻ뤷
wait Υơͤ嵭 W*() ޥȤäƲϤȤ
롼פ¹Ԥ롣

ΤΥ롦åϥץμ¹Ǥ:
.nf

$ ./a.out &
Child PID is 32360
[1] 32359
$ kill \-STOP 32360
stopped by signal 19
$ kill \-CONT 32360
continued
$ kill \-TERM 32360
killed by signal 15
[1]+  Done                    ./a.out
$

#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
    pid_t cpid, w;
    int status;

    cpid = fork();
    if (cpid == \-1) {
        perror("fork");
        exit(EXIT_FAILURE);
    }

    if (cpid == 0) {            /* Code executed by child */
        printf("Child PID is %ld\\n", (long) getpid());
        if (argc == 1)
            pause();                    /* Wait for signals */
        _exit(atoi(argv[1]));

    } else {                    /* Code executed by parent */
        do {
            w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
            if (w == \-1) {
                perror("waitpid");
                exit(EXIT_FAILURE);
            }

            if (WIFEXITED(status)) {
                printf("exited, status=%d\\n", WEXITSTATUS(status));
            } else if (WIFSIGNALED(status)) {
                printf("killed by signal %d\\n", WTERMSIG(status));
            } else if (WIFSTOPPED(status)) {
                printf("stopped by signal %d\\n", WSTOPSIG(status));
            } else if (WIFCONTINUED(status)) {
                printf("continued\\n");
            }
        } while (!WIFEXITED(status) && !WIFSIGNALED(status));
        exit(EXIT_SUCCESS);
    }
}
.fi
.SH Ϣ
.BR _exit (2),
.BR clone (2),
.BR fork (2),
.BR kill (2),
.BR ptrace (2),
.BR sigaction (2),
.BR signal (2),
.BR wait4 (2),
.BR pthread_create (3),
.BR credentials (7),
.BR signal (7)