wait.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 282 行

2
282
字号
.\" SCCSID: @(#)wait.2	2.1	3/10/87.TH wait 2.SH Namewait, wait3, waitpid \- wait for process to terminate.SH Syntax.nf.B #include <sys/types.h>.br.B #include <sys/wait.h>.PP.B pid = wait(\fIstatus\fP).B pid_t pid;.B union wait *\fIstatus\fP;.PP.B pid = wait((\fIunion wait*\fP)0).B pid_t pid;.PP.B #include <sys/time.h>.br.B #include <sys/resource.h>.PP.B pid = wait3(\fIstatus, options, rusage\fP).B pid_t pid;.B union wait *\fIstatus\fP;.B int \fIoptions\fP;.B struct \fIrusage *rusage\fP;.PP.B pid = waitpid(\fIpid, status, options\fP).B pid_t \fIpid\fP;.B union wait *\fIstatus\fP;.B int \fIoptions\fP;.fi.SH Description.NXR "wait system call".NXR "wait3 system call".NXR "waitpid system call".NXA "wait system call" "exit system call".NXR "process" "waiting for termination"The.PN waitsystem callcauses its caller to delay either until a signal is received orone of its childprocesses terminates.If a child process has died since the last.PN wait ,return is immediate, returning the process id and exit status of one of the terminated child processes.  If a child process does not exist, return is immediate, with the value \-1 returned..PPOn return from a successful .PN waitcall, if .I statusis nonzero, the high byte of .I statuscontains the low byte of the argument to.I exitsupplied by the child process;the low byte of .I statuscontains the termination status of the process.A more precise definition of the.I statusword is given in .PN <sys/wait.h> ..PPThe.PN wait3system callprovides an alternate interface for programsthat must not block when collecting the statusof child processes.  The.I statusparameter is defined as above.  The.I optionsparameter is used to indicate that the call should not block if there areno processes that wish to report status (WNOHANG),or that only children of the current process, which are stoppeddue to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal, should havetheir status reported (WUNTRACED).  If.I rusageis nonzero, a summary of the resources used by the terminatedprocess and all itschildren is returned (this information is not availablefor stopped processes)..PPWhen the WNOHANG option is specified and no processeswish to report status, .PN wait3returns a .I pidof zero (0).  The WNOHANG and WUNTRACED options can be combined by ORingthe two values..PPSee .MS sigvec 2for a list of termination statuses (signals).  A0 status indicates normal termination.A special status (0177) is returned for a process stopped by the process tracing mechanism,.MS ptrace 2 .If the 0200 bit of the termination statusis set,a core image of the process was producedby the system..PPIf the parent process terminates withoutwaiting on its children,the initialization process(process ID = 1)inherits the children..PPThe.PN waitpidsystem callprovides an interface for programs that want to wait for a specific child process orchild processes from specific process groups. The.PN waitpid system call behaves as follows:.IP \(bu 5If .IR pidis equal to \-1, status is requested for any child process..IP \(buIf.IR pidis greater than zero, it specifies the process ID of a single child process for which status is requested..IP \(buIf.IR pidis equal to zero, status is requested for any child process whose process group ID is equal to that of thecalling process..IP \(buIf.IR pidis less than \-1, status is requested for any child process whose process group ID is equal to the absolutevalue of.IR pid..PPThe.IR statusand.IR optionsarguments are defined as above.The.PN waitpidsystem callbehaves identically to the.PN waitsystem call, if the.I pidargument has a value of \-1 and the.I optionsargument has a value of zero (0)..PPThe.PN wait ,.PN wait3 ,and.PN waitpidsystem callsare automatically restarted when a process receives asignal while awaiting termination of a child process, unless theSV_INTERRUPT bit has been set for that signal. See .MS sigvec 2 ..PPThe following macros, defined in .PN <sys/wait.h> can be used to interpret the information contained in the.IR statusparameter returned by the wait functions; the .I stat_valargument is the value pointed to by the.I statusargument..IP "WIFEXITED(\fIstat_val\fP)"Evaluates to a nonzero value, if status was returned for a child process thatterminated normally..sp.IP "WEXITSTATUS(\fIstat_val\fP)"If the value of WIFEXITED(\fIstat_val\fP) is nonzero, this macro evaluates to the low-order eight bits of the .IR statusargument that the child process passes to .PN _exit or .PN exit ,or the value the child process returned from .PN main ..sp.IP "WIFSIGNALED(\fIstat_val\fP)"Evaluates to a nonzero value, if status was returned for a child process that terminateddue to the receipt of a signal that was not caught..sp.IP "WTERMSIG(\fIstat_val\fP)"If the value of WIFSIGNALED(\fIstat_val\fP) is nonzero, this macro evaluates to the number of thesignal that caused the termination of the child process..sp.IP "WIFSTOPPED(\fIstat_val\fP)"Evaluates to a nonzero value, if status was returned for a child process that is currently stopped..sp.IP "WSTOPSIG(\fIstat_val\fP)"If the value of WIFSTOPPED(\fIstat_val\fP) is nonzero, this macro evaluates to the number of thesignal that caused the child process to stop..SH Return ValuesIf .PN wait ,.PN wait3 ,or.PN waitpid returns 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 \fIerrno\fP is set to indicate the error..PPThe.PN wait3and.PN waitpidsystem callsreturn \-1, if there are no children not previously waitedfor.  A value of zero (0) is returned, if WNOHANG is specified and there areno stopped or exited children..SH Environment.NXR "wait system call" "System V and"SYSTEM_FIVE.PPWhen your program is compiled using the System V environment,when the SIGCLD signal is being ignored, .PN waitcontinues until all children terminate.SIGCLD is the same as SIGCHLD..PPIn addition, when using the System V environment, .I statusis of type int *..PPPOSIX.PPWhen using the POSIX environment,.I statusis of type int *..PPIn addition, the SV_INTERRUPT flag is always set in POSIX mode, causing theabove system calls to always fail, if interrupted by a signal..SH Diagnostics.NXR "wait system call" "diagnostics"The.PN wait ,.PN wait3 ,or.PN waitpidsystem callsfail and return is immediate, if any of the followingis true:.TP 15[ECHILD]The calling process has no existing unwaited-forchild processes..TP 15[ECHILD]The process or process group specified by \fIpid\fP does not exist or is nota child of the calling process..TP 15[EINTR]The function was interrupted by a signal. The value of the location pointed toby.IR statusis undefined..TP 15[EINVAL]The value of the \fIoptions\fP argument is not valid..TP 15[EFAULT]The \fIstatus\fP or \fIrusage\fP arguments point to an illegal address..SH See Alsoexit(2), ptrace(2), sigvec(2)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?