📄 wait.2
字号:
.\" Copyright (c) 1980, 1991, 1993, 1994.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)wait.2 8.2 (Berkeley) 4/19/94.\".Dd April 19, 1994.Dt WAIT 2.Os BSD 4.Sh NAME.Nm wait ,.Nm waitpid ,.Nm wait4 ,.Nm wait3.Nd wait for process termination.Sh SYNOPSIS.Fd #include <sys/types.h>.Fd #include <sys/wait.h>.Ft pid_t.Fn wait "int *status".Fd #include <sys/time.h>.Fd #include <sys/resource.h>.Ft pid_t.Fn waitpid "pid_t wpid" "int *status" "int options".Ft pid_t.Fn wait3 "int *status" "int options" "struct rusage *rusage".Ft pid_t.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage".Sh DESCRIPTIONThe.Fn waitfunction suspends execution of its calling process until.Fa statusinformation is available for a terminated child process,or a signal is received.On return from a successful .Fn waitcall, the.Fa statusarea contains termination information about the process that exitedas defined below..PpThe.Fn wait4call provides a more general interface for programsthat need to wait for certain child processes,that need resource utilization statistics accumulated by child processes,or that require options.The other wait functions are implemented using.Fn wait4 ..PpThe.Fa wpidparameter specifies the set of child processes for which to wait.If.Fa wpidis -1, the call waits for any child process.If.Fa wpidis 0,the call waits for any child process in the process group of the caller.If.Fa wpidis greater than zero, the call waits for the process with process id.Fa wpid .If.Fa wpidis less than -1, the call waits for any process whose process group idequals the absolute value of.Fa wpid ..PpThe.Fa statusparameter is defined below. The.Fa optionsparameter contains the bitwise OR of any of the following options.The.Dv WNOHANGoptionis used to indicate that the call should not block ifthere are no processes that wish to report status.If the.Dv WUNTRACEDoption is set,children of the current process that are stoppeddue to a.Dv SIGTTIN , SIGTTOU , SIGTSTP ,or.Dv SIGSTOPsignal also havetheir status reported..PpIf.Fa rusageis non-zero, a summary of the resources used by the terminatedprocess and all itschildren is returned (this information is currently not availablefor stopped processes)..PpWhen the.Dv WNOHANGoption is specified and no processeswish to report status, .Fn wait4returns a process idof 0..PpThe.Fn waitpidcall is identical to.Fn wait4with an.Fa rusagevalue of zero.The older.Fn wait3call is the same as.Fn wait4with a.Fa wpidvalue of -1..PpThe following macros may be used to test the manner of exit of the process.One of the first three macros will evaluate to a non-zero (true) value:.Bl -tag -width Ds.It Fn WIFEXITED statusTrue if the process terminated normally by a call to.Xr _exit 2or.Xr exit 2 ..It Fn WIFSIGNALED statusTrue if the process terminated due to receipt of a signal..It Fn WIFSTOPPED statusTrue if the process has not terminated, but has stopped and can be restarted.This macro can be true only if the wait call specified the.Dv WUNTRACEDoptionor if the child process is being traced (see.Xr ptrace 2 ) ..El.PpDepending on the values of those macros, the following macrosproduce the remaining status information about the child process:.Bl -tag -width Ds.It Fn WEXITSTATUS statusIf.Fn WIFEXITED statusis true, evaluates to the low-order 8 bitsof the argument passed to.Xr _exit 2or.Xr exit 2by the child..It Fn WTERMSIG statusIf.Fn WIFSIGNALED statusis true, evaluates to the number of the signalthat caused the termination of the process..It Fn WCOREDUMP statusIf.Fn WIFSIGNALED statusis true, evaluates as true if the terminationof the process was accompanied by the creation of a core filecontaining an image of the process when the signal was received..It Fn WSTOPSIG statusIf.Fn WIFSTOPPED statusis true, evaluates to the number of the signalthat caused the process to stop..El.Sh NOTESSee.Xr sigaction 2for a list of termination signals.A status of 0 indicates normal termination..PpIf a parent process terminates withoutwaiting for all of its child processes to terminate,the remaining child processes are assigned the parentprocess 1 ID (the init process ID)..PpIf a signal is caught while any of the.Fn waitcalls is pending,the call may be interrupted or restarted when the signal-catching routinereturns,depending on the options in effect for the signal;see.Xr intro 2 ,System call restart..Sh RETURN VALUESIf.Fn waitreturns due to a stoppedor terminated child process, the process ID of the childis returned to the calling process. Otherwise, a value of -1is returned and.Va errnois set to indicate the error..PpIf.Fn wait4 ,.Fn wait3or.Fn waitpidreturns due to a stoppedor terminated child process, the process ID of the childis returned to the calling process.If there are no children not previously awaited,-1 is returned with.Va errnoset to.Bq Er ECHILD .Otherwise, if.Dv WNOHANGis specified and there areno stopped or exited children,0 is returned.If an error is detected or a caught signal aborts the call,a value of -1is returned and.Va errnois set to indicate the error..Sh ERRORS.Fn Waitwill fail and return immediately if:.Bl -tag -width Er.It Bq Er ECHILDThe calling process has no existing unwaited-forchild processes..It Bq Er EFAULTThe.Fa statusor.Fa rusagearguments point to an illegal address.(May not be detected before exit of a child process.).It Bq Er EINTRThe call was interrupted by a caught signal,or the signal did not have the.Dv SA_RESTARTflag set..El.Sh STANDARDSThe.Fn waitand.Fn waitpidfunctions are defined by POSIX;.Fn wait4and.Fn wait3are not specified by POSIX.The.Fn WCOREDUMPmacroand the ability to restart a pending.Fn waitcall are extensions to the POSIX interface..Sh SEE ALSO.Xr exit 2 ,.Xr sigaction 2.Sh HISTORYA.Nmfunction call appeared in Version 6 AT&T UNIX.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -