HP 3000 Manuals

wait [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

wait 

Suspends the calling process to wait for exit status of child processes.

Syntax 

     #include <sys/types.h>
     #include <sys/wait.h>
     pid_t wait (int *stat_loc);

Parameters 

stat_loc   A pointer to the exit status of the child process.  No
           information is returned if stat_loc is NULL.

Return Values 

>0         Success.  The process ID of a child process that has
           terminated is returned.

-1         An error occurred.  There is no result, and errno is set to
           indicate the error condition.

Description 

The wait() function suspends the calling process until status information
for one of its terminated child processes is available.  If status
information is already available, wait() returns immediately.

If the calling process receives a signal whose action is to terminate,
the calling process terminates.  If the calling process receives a signal
whose action is to execute a signal handling function, wait() returns to
the calling process.

If status is available for more than one process, the order in which
their status is reported may not correspond to the order of their
termination.

The wait() function returns to the argument pointed to by stat_loc an
exit status of 0 if, and only if, the child process that returned status
took one of the following two actions:

   *   returned a value of zero from its main() function (outer block)

   *   passed a status value of zero to _exit() or exit()

The following macros that evaluate the stat_loc parameter, regardless of
its value, are defined in the header <sys/wait.h>:

WIFEXITED(exit_status)    Evaluates to a nonzero value if status was
                          returned for a child process that terminated
                          normally.
WEXITSTATUS(exit_status)  If WIFEXITED is nonzero, this macro evaluates
                          to the low-order 8 bits of the stat_loc 
                          parameter that the child process passed to
                          _exit() or exit(), or the value that the child
                          process returned from main().
WIFSIGNALED(exit_status)  Evaluates to a nonzero value if status was
                          returned for a child process that terminated
                          due to the receipt of a signal that was not
                          caught.
WTERMSIG(exit_status)     If WIFSIGNALED is nonzero, this macro evaluates
                          to the number of the signal that caused the
                          termination of the child process.
WIFSTOPPED(exit_status)   Evaluates to a nonzero value if status was
                          returned for a child process that is currently
                          stopped.
WSTOPSIG(exit_status)     If WIFSTOPPED is nonzero, this macro evaluates
                          to the number of the signal that caused the
                          child process to stop.

Implementation Considerations 

Refer to the EFAULT error description below.

If a parent process terminates without waiting for all of its child
processes to terminate, the remaining child processes are terminated.

Errors 

If an error occurs, errno is set to one of the following values:

ECHILD            CAUSE           The calling process has no unwaited-for child
                                  processes.
                  ACTION          No action is necessary.

EFAULT            CAUSE           The system detected a bad address in attempting to
                                  use the stat_loc parameter.
                  ACTION          Make sure that the pointer is correctly initialized.

EINTR             CAUSE           The function was interrupted by a signal.  The
                                  stat_loc parameter's value is undefined.
                  ACTION          Call the wait() function again to continue waiting.

See Also 

_exit(), fork(), pause(), waitpid(), <signal.h>, POSIX.1 (Section 3.2.1)



MPE/iX 5.0 Documentation