await, wait, waitpid – wait for a process to exit
int await(char *s, int n)
causes a process to wait for any child process (see
It returns a
information about the exited child.
has this structure:
int pid; /* of loved one */
ulong time; /* of loved one & descendants */
is the child’s
array contains the time the child and its descendants spent in user code,
the time spent in system calls, and the child’s elapsed real time,
all in units of milliseconds.
contains the message that the child specified in
For a normal exit,
is the exit string
prefixed by the process name, a blank, the process id, and a colon.
If there are no more children to wait for,
returns immediately, with return value nil.
structure is allocated by
and should be freed after use.
For programs that only need the pid of the exiting program,
returns just the pid and discards the rest of the information.
The underlying system call is
which fills in the n-byte buffer
with a textual representation of the pid, times, and exit string.
There is no terminal NUL.
The return value is the length, in bytes, of the data.
The buffer filled in by
may be parsed (after appending a NUL) using
the resulting fields are, in order, pid, the three times, and the exit string,
which will be
for normal exit.
If the representation is longer than
bytes, it is truncated but, if possible, properly formatted.
The information that does not fit in the buffer is discarded, so
a subsequent call to
will return the information about the next exiting child, not the remainder
of the truncated message.
In other words, each call to
returns the information about one child, blocking if necessary if no child has exited.
If the calling process has no living children,
These routines set