Blame


1 cfa37a7b 2004-04-10 devnull .TH WAIT 3
2 cfa37a7b 2004-04-10 devnull .SH NAME
3 058b0118 2005-01-03 devnull await, awaitnohang, awaitfor, wait, waitnohang, waitfor, 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 058b0118 2005-01-03 devnull Waitmsg* waitnohang(void)
14 058b0118 2005-01-03 devnull .PP
15 058b0118 2005-01-03 devnull .B
16 058b0118 2005-01-03 devnull Waitmsg* waitfor(int pid)
17 058b0118 2005-01-03 devnull .PP
18 058b0118 2005-01-03 devnull .B
19 cfa37a7b 2004-04-10 devnull int waitpid(void)
20 cfa37a7b 2004-04-10 devnull .PP
21 cfa37a7b 2004-04-10 devnull .B
22 cfa37a7b 2004-04-10 devnull int await(char *s, int n)
23 058b0118 2005-01-03 devnull .PP
24 058b0118 2005-01-03 devnull .B
25 058b0118 2005-01-03 devnull int awaitnohang(char *s, int n)
26 058b0118 2005-01-03 devnull .PP
27 058b0118 2005-01-03 devnull .B
28 058b0118 2005-01-03 devnull int awaitfor(int pid, char *s, int n)
29 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
30 cfa37a7b 2004-04-10 devnull .I Wait
31 cfa37a7b 2004-04-10 devnull causes a process to wait for any child process (see
32 d32deab1 2020-08-16 rsc .MR fork (2)
33 058b0118 2005-01-03 devnull and
34 d32deab1 2020-08-16 rsc .MR rfork (3) )
35 cfa37a7b 2004-04-10 devnull to exit.
36 cfa37a7b 2004-04-10 devnull It returns a
37 cfa37a7b 2004-04-10 devnull .B Waitmsg
38 cfa37a7b 2004-04-10 devnull holding
39 cfa37a7b 2004-04-10 devnull information about the exited child.
40 cfa37a7b 2004-04-10 devnull A
41 cfa37a7b 2004-04-10 devnull .B Waitmsg
42 cfa37a7b 2004-04-10 devnull has this structure:
43 cfa37a7b 2004-04-10 devnull .IP
44 cfa37a7b 2004-04-10 devnull .EX
45 cfa37a7b 2004-04-10 devnull .ta 6n +\w'long 'u +\w'msg[ERRLEN]; 'u
46 cfa37a7b 2004-04-10 devnull typedef
47 cfa37a7b 2004-04-10 devnull struct Waitmsg
48 cfa37a7b 2004-04-10 devnull {
49 cfa37a7b 2004-04-10 devnull int pid; /* of loved one */
50 cfa37a7b 2004-04-10 devnull ulong time[3]; /* of loved one & descendants */
51 cfa37a7b 2004-04-10 devnull char *msg;
52 cfa37a7b 2004-04-10 devnull } Waitmsg;
53 cfa37a7b 2004-04-10 devnull .EE
54 cfa37a7b 2004-04-10 devnull .PP
55 cfa37a7b 2004-04-10 devnull .B Pid
56 cfa37a7b 2004-04-10 devnull is the child's
57 cfa37a7b 2004-04-10 devnull process id.
58 cfa37a7b 2004-04-10 devnull The
59 cfa37a7b 2004-04-10 devnull .B time
60 cfa37a7b 2004-04-10 devnull array contains the time the child and its descendants spent in user code,
61 cfa37a7b 2004-04-10 devnull the time spent in system calls, and the child's elapsed real time,
62 cfa37a7b 2004-04-10 devnull all in units of milliseconds.
63 cfa37a7b 2004-04-10 devnull .B Msg
64 cfa37a7b 2004-04-10 devnull contains the message that the child specified in
65 d32deab1 2020-08-16 rsc .MR exits (3) .
66 cfa37a7b 2004-04-10 devnull For a normal exit,
67 cfa37a7b 2004-04-10 devnull .B msg[0]
68 cfa37a7b 2004-04-10 devnull is zero,
69 cfa37a7b 2004-04-10 devnull otherwise
70 cfa37a7b 2004-04-10 devnull .B msg
71 cfa37a7b 2004-04-10 devnull is the exit string
72 cfa37a7b 2004-04-10 devnull prefixed by the process name, a blank, the process id, and a colon.
73 cfa37a7b 2004-04-10 devnull .PP
74 cfa37a7b 2004-04-10 devnull If there are no more children to wait for,
75 cfa37a7b 2004-04-10 devnull .I wait
76 cfa37a7b 2004-04-10 devnull returns immediately, with return value nil.
77 cfa37a7b 2004-04-10 devnull .PP
78 cfa37a7b 2004-04-10 devnull The
79 cfa37a7b 2004-04-10 devnull .B Waitmsg
80 cfa37a7b 2004-04-10 devnull structure is allocated by
81 d32deab1 2020-08-16 rsc .MR malloc (3)
82 cfa37a7b 2004-04-10 devnull and should be freed after use.
83 cfa37a7b 2004-04-10 devnull For programs that only need the pid of the exiting program,
84 cfa37a7b 2004-04-10 devnull .I waitpid
85 cfa37a7b 2004-04-10 devnull returns just the pid and discards the rest of the information.
86 cfa37a7b 2004-04-10 devnull .PP
87 058b0118 2005-01-03 devnull .I Waitnohang
88 058b0118 2005-01-03 devnull is like
89 058b0118 2005-01-03 devnull .I wait
90 058b0118 2005-01-03 devnull but does not block if there are no more children to wait for.
91 058b0118 2005-01-03 devnull Instead it returns immediately and sets
92 058b0118 2005-01-03 devnull .IR errstr .
93 058b0118 2005-01-03 devnull .PP
94 058b0118 2005-01-03 devnull .I Waitfor
95 058b0118 2005-01-03 devnull is like
96 058b0118 2005-01-03 devnull .I wait
97 058b0118 2005-01-03 devnull but waits for a particular
98 058b0118 2005-01-03 devnull .IR pid .
99 058b0118 2005-01-03 devnull .PP
100 058b0118 2005-01-03 devnull The underlying calls are
101 cfa37a7b 2004-04-10 devnull .IR await ,
102 058b0118 2005-01-03 devnull .IR awaitnohang ,
103 058b0118 2005-01-03 devnull and
104 058b0118 2005-01-03 devnull .IR awaitfor ,
105 058b0118 2005-01-03 devnull which fill in the
106 058b0118 2005-01-03 devnull .IR n -byte
107 058b0118 2005-01-03 devnull buffer
108 cfa37a7b 2004-04-10 devnull .I s
109 cfa37a7b 2004-04-10 devnull with a textual representation of the pid, times, and exit string.
110 cfa37a7b 2004-04-10 devnull There is no terminal NUL.
111 cfa37a7b 2004-04-10 devnull The return value is the length, in bytes, of the data.
112 cfa37a7b 2004-04-10 devnull .PP
113 058b0118 2005-01-03 devnull The filled-in buffer
114 cfa37a7b 2004-04-10 devnull may be parsed (after appending a NUL) using
115 cfa37a7b 2004-04-10 devnull .IR tokenize
116 cfa37a7b 2004-04-10 devnull (see
117 d32deab1 2020-08-16 rsc .MR getfields (3) );
118 cfa37a7b 2004-04-10 devnull the resulting fields are, in order, pid, the three times, and the exit string,
119 cfa37a7b 2004-04-10 devnull which will be
120 cfa37a7b 2004-04-10 devnull .B ''
121 cfa37a7b 2004-04-10 devnull for normal exit.
122 cfa37a7b 2004-04-10 devnull If the representation is longer than
123 cfa37a7b 2004-04-10 devnull .I n
124 cfa37a7b 2004-04-10 devnull bytes, it is truncated but, if possible, properly formatted.
125 cfa37a7b 2004-04-10 devnull The information that does not fit in the buffer is discarded, so
126 cfa37a7b 2004-04-10 devnull a subsequent call to
127 cfa37a7b 2004-04-10 devnull .I await
128 cfa37a7b 2004-04-10 devnull will return the information about the next exiting child, not the remainder
129 cfa37a7b 2004-04-10 devnull of the truncated message.
130 cfa37a7b 2004-04-10 devnull In other words, each call to
131 cfa37a7b 2004-04-10 devnull .I await
132 cfa37a7b 2004-04-10 devnull returns the information about one child, blocking if necessary if no child has exited.
133 cfa37a7b 2004-04-10 devnull If the calling process has no living children,
134 cfa37a7b 2004-04-10 devnull .I await
135 cfa37a7b 2004-04-10 devnull returns
136 cfa37a7b 2004-04-10 devnull .BR -1 .
137 cfa37a7b 2004-04-10 devnull .SH SOURCE
138 c3674de4 2005-01-11 devnull .B \*9/src/lib9/wait.c
139 058b0118 2005-01-03 devnull .PP
140 c3674de4 2005-01-11 devnull .B \*9/src/lib9/await.c
141 cfa37a7b 2004-04-10 devnull .SH "SEE ALSO"
142 d32deab1 2020-08-16 rsc .MR rfork (3) ,
143 d32deab1 2020-08-16 rsc .MR exits (3) ,
144 cfa37a7b 2004-04-10 devnull .SH DIAGNOSTICS
145 cfa37a7b 2004-04-10 devnull These routines set
146 cfa37a7b 2004-04-10 devnull .IR errstr .
147 c8b6342d 2005-01-13 devnull .SH BUGS
148 c8b6342d 2005-01-13 devnull To avoid name conflicts with the underlying system,
149 c8b6342d 2005-01-13 devnull .IR wait ,
150 c8b6342d 2005-01-13 devnull .IR waitpid ,
151 c8b6342d 2005-01-13 devnull and
152 c8b6342d 2005-01-13 devnull .I waitfor
153 c8b6342d 2005-01-13 devnull are preprocessor macros defined as
154 c8b6342d 2005-01-13 devnull .IR p9wait ,
155 c8b6342d 2005-01-13 devnull .IR p9waitpid ,
156 c8b6342d 2005-01-13 devnull and
157 c8b6342d 2005-01-13 devnull .IR p9waitfor ;
158 c8b6342d 2005-01-13 devnull see
159 d32deab1 2020-08-16 rsc .MR intro (3) .