Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exit(2)

getrusage(2)

ptrace(2)

sigvec(2)



WAIT(2)                 COMMAND REFERENCE                 WAIT(2)



NAME
     wait, wait3 - wait for process to terminate

SYNOPSIS
     #include <sys/wait.h>

     pid = wait(status)
     int pid;
     union wait *status;

     pid = wait(0)
     int pid;

     #include <sys/time.h>
     #include <sys/resource.h>

     pid = wait3(status, options, rusage)
     int pid;
     union wait *status;
     int options;
     struct rusage *rusage;

DESCRIPTION
     Wait suspends the calling process until it receives a signal
     or one of its child processes terminates.  If any child is
     terminated prior to the call on wait, return is immediate,
     returning in pid the process ID and in status the exit
     status of one of the terminated children.  If there are no
     children, return is immediate with pid set to -1.

     On return from a successful wait call, status is nonzero,
     and the high byte of status contains the low byte of the
     argument to exit supplied by the child process; the low byte
     of status contains the termination status of the process.  A
     more precise definition of the status word is given in
     <sys/wait.h>:

          union wait  {
            int   w_status;   /* used in syscall */
            /*
            * Terminated process status.
            */
            struct   {
               unsigned short:  16;          /*pad to make full 32 bits */
               unsigned short   w_Retcode:8; /* exit code if w_termsig==0 */
               unsigned short   w_Coredump:1;     /* core dump indicator */
               unsigned short   w_Termsig:7; /* termination signal */
            } w_T;
               /*
               * Stopped process status.  Returned
               * only for traced children unless requested
               * with the WUNTRACED option bit.



Printed 4/6/89                                                  1





WAIT(2)                 COMMAND REFERENCE                 WAIT(2)



               */
            struct {
               unsigned short: 16;      /*pad to make full 32 bits */
               unsigned short  w_Stopsig:8;  /* signal that stopped us */
               unsigned short  w_Stopval:8;  /* == W_STOPPED if stopped */
            } w_S;
          };

     If wait is called with an argument of 0, no status
     information is returned.

     Wait3 provides an alternate interface for programs which
     must not block when collecting the status of child
     processes.  The status parameter is defined as above.  The
     options parameter is one of the following, defined in
     <sys/wait.h>:

          #define WNOHANG     1    /* don't hang in wait */
          #define WUNTRACED   2    /* tell about stopped, untraced children */

     Options is used to indicate the call should not block if
     there are no processes which wish to report status
     (WNOHANG), and/or that only children of the current process
     which are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or
     SIGSTOP signal should have their status reported
     (WUNTRACED).  If rusage is non-zero, a summary of the
     resources used by the terminated process and all its
     children is returned in rusage (this information is
     currently not available for stopped processes).  See
     getrusage(2).

     If rusage is NULL, no resource information is returned.

     When the WNOHANG option is specified and no processes wish
     to report status, wait3 returns a pid of 0.  The WNOHANG and
     WUNTRACED options may be combined by or'ing the two values.

     See sigvec(2) for a list of termination statuses (signals);
     0 status indicates normal termination.  A special status
     (0177) is returned for a stopped process which has not
     terminated and can be restarted; see ptrace(2).  If the 0200
     bit of the termination status is set, a core image of the
     process was produced by the system.

     If the parent process terminates without waiting on its
     children, the initialization process (process ID = 1)
     inherits the children.

     Wait and wait3 are automatically restarted when a process
     receives a signal while awaiting termination of a child
     process.




Printed 4/6/89                                                  2





WAIT(2)                 COMMAND REFERENCE                 WAIT(2)



DIAGNOSTICS
     Wait and wait3 will fail and return immediately if one or
     more of the following are true:

     [ECHILD]     The calling process has no existing unwaited-
                  for child processes.

     [EFAULT]     The status or rusage arguments point to an
                  illegal address.

RETURN VALUE
     If wait or wait3 return due to a stopped or terminated child
     process, the process ID of the child is returned to the
     calling process in pid and the exit status of the child is
     returned in status. Otherwise, a value of -1 is returned in
     pid and errno is set to indicate the error.

     Wait3 returns 0 if WNOHANG is specified and there are no
     stopped or exited children.

SEE ALSO
     exit(2), getrusage(2), ptrace(2), and sigvec(2).

































Printed 4/6/89                                                  3



%%index%%
na:240,95;
sy:335,2492;
de:2827,1696;4835,2526;
di:7673,538;
rv:8211,699;
se:8910,221;
%%index%%000000000120

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026