int pid; /* of loved one */
ulong time; /* of loved one & descendants */
char*msg; } Waitmsg;
If there are no more children to wait for, wait returns immediately, with return value nil.
The Waitmsg structure is allocated by malloc(3) and should be freed after use. For programs that only need the pid of the exiting program, waitpid returns just the pid and discards the rest of the information.
Waitnohang is like wait but does not block if there are no more children to wait for. Instead it returns immediately and sets errstr.
Waitfor is like wait but waits for a particular pid.
The underlying calls are await, awaitnohang, and awaitfor, which fill in the n-byte buffer s 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 filled-in buffer may be parsed (after appending a NUL) using tokenize (see getfields(3)); 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 n 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 await will return the information about the next exiting child, not the remainder of the truncated message. In other words, each call to await returns the information about one child, blocking if necessary if no child has exited. If the calling process has no living children, await returns -1.
These routines set errstr.
To avoid name conflicts with the underlying system, wait, waitpid, and waitfor are preprocessor macros defined as p9wait, p9waitpid, and p9waitfor; see intro(3).