Blame


1 cfa37a7b 2004-04-10 devnull .TH WAIT 3
2 cfa37a7b 2004-04-10 devnull .SH NAME
3 cfa37a7b 2004-04-10 devnull await, wait, waitpid \- wait for a process to exit
4 cfa37a7b 2004-04-10 devnull .SH SYNOPSIS
5 cfa37a7b 2004-04-10 devnull .B #include <u.h>
6 cfa37a7b 2004-04-10 devnull .br
7 cfa37a7b 2004-04-10 devnull .B #include <libc.h>
8 cfa37a7b 2004-04-10 devnull .PP
9 cfa37a7b 2004-04-10 devnull .B
10 cfa37a7b 2004-04-10 devnull Waitmsg* wait(void)
11 cfa37a7b 2004-04-10 devnull .PP
12 cfa37a7b 2004-04-10 devnull .B
13 cfa37a7b 2004-04-10 devnull int waitpid(void)
14 cfa37a7b 2004-04-10 devnull .PP
15 cfa37a7b 2004-04-10 devnull .B
16 cfa37a7b 2004-04-10 devnull int await(char *s, int n)
17 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
18 cfa37a7b 2004-04-10 devnull .I Wait
19 cfa37a7b 2004-04-10 devnull causes a process to wait for any child process (see
20 bf8a59fa 2004-04-11 devnull .IR fork (3))
21 cfa37a7b 2004-04-10 devnull to exit.
22 cfa37a7b 2004-04-10 devnull It returns a
23 cfa37a7b 2004-04-10 devnull .B Waitmsg
24 cfa37a7b 2004-04-10 devnull holding
25 cfa37a7b 2004-04-10 devnull information about the exited child.
26 cfa37a7b 2004-04-10 devnull A
27 cfa37a7b 2004-04-10 devnull .B Waitmsg
28 cfa37a7b 2004-04-10 devnull has this structure:
29 cfa37a7b 2004-04-10 devnull .IP
30 cfa37a7b 2004-04-10 devnull .EX
31 cfa37a7b 2004-04-10 devnull .ta 6n +\w'long 'u +\w'msg[ERRLEN]; 'u
32 cfa37a7b 2004-04-10 devnull typedef
33 cfa37a7b 2004-04-10 devnull struct Waitmsg
34 cfa37a7b 2004-04-10 devnull {
35 cfa37a7b 2004-04-10 devnull int pid; /* of loved one */
36 cfa37a7b 2004-04-10 devnull ulong time[3]; /* of loved one & descendants */
37 cfa37a7b 2004-04-10 devnull char *msg;
38 cfa37a7b 2004-04-10 devnull } Waitmsg;
39 cfa37a7b 2004-04-10 devnull .EE
40 cfa37a7b 2004-04-10 devnull .PP
41 cfa37a7b 2004-04-10 devnull .B Pid
42 cfa37a7b 2004-04-10 devnull is the child's
43 cfa37a7b 2004-04-10 devnull process id.
44 cfa37a7b 2004-04-10 devnull The
45 cfa37a7b 2004-04-10 devnull .B time
46 cfa37a7b 2004-04-10 devnull array contains the time the child and its descendants spent in user code,
47 cfa37a7b 2004-04-10 devnull the time spent in system calls, and the child's elapsed real time,
48 cfa37a7b 2004-04-10 devnull all in units of milliseconds.
49 cfa37a7b 2004-04-10 devnull .B Msg
50 cfa37a7b 2004-04-10 devnull contains the message that the child specified in
51 bf8a59fa 2004-04-11 devnull .IR exits (3).
52 cfa37a7b 2004-04-10 devnull For a normal exit,
53 cfa37a7b 2004-04-10 devnull .B msg[0]
54 cfa37a7b 2004-04-10 devnull is zero,
55 cfa37a7b 2004-04-10 devnull otherwise
56 cfa37a7b 2004-04-10 devnull .B msg
57 cfa37a7b 2004-04-10 devnull is the exit string
58 cfa37a7b 2004-04-10 devnull prefixed by the process name, a blank, the process id, and a colon.
59 cfa37a7b 2004-04-10 devnull .PP
60 cfa37a7b 2004-04-10 devnull If there are no more children to wait for,
61 cfa37a7b 2004-04-10 devnull .I wait
62 cfa37a7b 2004-04-10 devnull returns immediately, with return value nil.
63 cfa37a7b 2004-04-10 devnull .PP
64 cfa37a7b 2004-04-10 devnull The
65 cfa37a7b 2004-04-10 devnull .B Waitmsg
66 cfa37a7b 2004-04-10 devnull structure is allocated by
67 bf8a59fa 2004-04-11 devnull .IR malloc (3)
68 cfa37a7b 2004-04-10 devnull and should be freed after use.
69 cfa37a7b 2004-04-10 devnull For programs that only need the pid of the exiting program,
70 cfa37a7b 2004-04-10 devnull .I waitpid
71 cfa37a7b 2004-04-10 devnull returns just the pid and discards the rest of the information.
72 cfa37a7b 2004-04-10 devnull .PP
73 cfa37a7b 2004-04-10 devnull The underlying system call is
74 cfa37a7b 2004-04-10 devnull .IR await ,
75 cfa37a7b 2004-04-10 devnull which fills in the n-byte buffer
76 cfa37a7b 2004-04-10 devnull .I s
77 cfa37a7b 2004-04-10 devnull with a textual representation of the pid, times, and exit string.
78 cfa37a7b 2004-04-10 devnull There is no terminal NUL.
79 cfa37a7b 2004-04-10 devnull The return value is the length, in bytes, of the data.
80 cfa37a7b 2004-04-10 devnull .PP
81 cfa37a7b 2004-04-10 devnull The buffer filled in by
82 cfa37a7b 2004-04-10 devnull .I await
83 cfa37a7b 2004-04-10 devnull may be parsed (after appending a NUL) using
84 cfa37a7b 2004-04-10 devnull .IR tokenize
85 cfa37a7b 2004-04-10 devnull (see
86 bf8a59fa 2004-04-11 devnull .IR getfields (3));
87 cfa37a7b 2004-04-10 devnull the resulting fields are, in order, pid, the three times, and the exit string,
88 cfa37a7b 2004-04-10 devnull which will be
89 cfa37a7b 2004-04-10 devnull .B ''
90 cfa37a7b 2004-04-10 devnull for normal exit.
91 cfa37a7b 2004-04-10 devnull If the representation is longer than
92 cfa37a7b 2004-04-10 devnull .I n
93 cfa37a7b 2004-04-10 devnull bytes, it is truncated but, if possible, properly formatted.
94 cfa37a7b 2004-04-10 devnull The information that does not fit in the buffer is discarded, so
95 cfa37a7b 2004-04-10 devnull a subsequent call to
96 cfa37a7b 2004-04-10 devnull .I await
97 cfa37a7b 2004-04-10 devnull will return the information about the next exiting child, not the remainder
98 cfa37a7b 2004-04-10 devnull of the truncated message.
99 cfa37a7b 2004-04-10 devnull In other words, each call to
100 cfa37a7b 2004-04-10 devnull .I await
101 cfa37a7b 2004-04-10 devnull returns the information about one child, blocking if necessary if no child has exited.
102 cfa37a7b 2004-04-10 devnull If the calling process has no living children,
103 cfa37a7b 2004-04-10 devnull .I await
104 cfa37a7b 2004-04-10 devnull returns
105 cfa37a7b 2004-04-10 devnull .BR -1 .
106 cfa37a7b 2004-04-10 devnull .SH SOURCE
107 b5fdffee 2004-04-19 devnull .B /usr/local/plan9/src/libc/9syscall
108 cfa37a7b 2004-04-10 devnull .SH "SEE ALSO"
109 bf8a59fa 2004-04-11 devnull .IR fork (3),
110 bf8a59fa 2004-04-11 devnull .IR exits (3),
111 cfa37a7b 2004-04-10 devnull the
112 cfa37a7b 2004-04-10 devnull .B wait
113 cfa37a7b 2004-04-10 devnull file in
114 cfa37a7b 2004-04-10 devnull .IR proc (3)
115 cfa37a7b 2004-04-10 devnull .SH DIAGNOSTICS
116 cfa37a7b 2004-04-10 devnull These routines set
117 cfa37a7b 2004-04-10 devnull .IR errstr .