122 lines · 2.5 KB · Text
RawDownload
.TH WAIT 2.SH NAMEawait, wait, waitpid \- wait for a process to exit.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.BWaitmsg*	wait(void).PP.Bint 		waitpid(void).PP.Bint 		await(char *s, int n).SH DESCRIPTION.I Waitcauses a process to wait for any child process (see.IR fork (2))to exit.It returns a.B Waitmsgholdinginformation about the exited child.A.B Waitmsghas this structure:.IP.EX.ta 6n +\w'long 'u +\w'msg[ERRLEN];     'utypedefstruct Waitmsg{	int pid;	/* of loved one */	ulong time[3];	/* of loved one & descendants */	char	*msg;} Waitmsg;.EE.PP.B Pidis the child'sprocess id.The.B timearray 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..B Msgcontains the message that the child specified in.IR exits (2).For a normal exit,.B msg[0]is zero,otherwise.B msgis the exit stringprefixed by the process name, a blank, the process id, and a colon..PPIf there are no more children to wait for,.I waitreturns immediately, with return value nil..PPThe.B Waitmsgstructure is allocated by.IR malloc (2)and should be freed after use.For programs that only need the pid of the exiting program,.I waitpidreturns just the pid and discards the rest of the information..PPThe underlying system call is.IR await ,which fills in the n-byte buffer.I swith 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..PPThe buffer filled in by.I awaitmay be parsed (after appending a NUL) using.IR tokenize(see.IR getfields (2));the resulting fields are, in order, pid, the three times, and the exit string,which will be.B ''for normal exit.If the representation is longer than.I nbytes, it is truncated but, if possible, properly formatted.The information that does not fit in the buffer is discarded, soa subsequent call to.I awaitwill return the information about the next exiting child, not the remainderof the truncated message.In other words, each call to.I awaitreturns the information about one child, blocking if necessary if no child has exited..PPIf the calling process has no living children,.I awaitand.I waitpidreturn.BR -1 ..SH SOURCE.B /sys/src/libc/9syscall.br.B /sys/src/libc/9sys.SH "SEE ALSO".IR fork (2),.IR exits (2),the.B waitfile in.IR proc (3).SH DIAGNOSTICSThese routines set.IR errstr .