wait()

wait for process termination 

Function


SYNOPSIS

#include <sys/types.h>

#include <sys/wait.h>

pid_t wait(int *stat_loc);


DESCRIPTION

The wait() function lets the calling process obtain status information about one of its child processes. If status information is available for two or more child processes, the order in which their status is reported is unspecified. If more than one thread is suspended in wait() awaiting termination of the same process, exactly one thread returns the process status at the time of the target child process termination. The other threads return -1, with errno set to ECHILD.

If the calling process sets SIGCHLD to SIG_IGN, and the process has no unwaited for children that were transformed into zombie processes, the calling thread blocks until all of the children of the process terminate, at which time wait() returns -1 with errno set to ECHILD.

If the parent process terminates without waiting for all of its child processes to terminate, the remaining child processes is assigned a new parent process ID corresponding to a system-level process.


PARAMETERS

stat_loc 

Specifies the location where the child process' exit status is stored. If NULL is passed, no exit status is returned. Otherwise, the following macros defined in <sys/wait.h> can be used to evaluate the returned status:

WIFEXITED(s) 

Evaluates to a non-zero value if status was returned for a child process that exited normally.

WEXITSTATUS(s) 

If the value of WIFEXITED(s) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to exit() or _exit(), or the value the child process returned from main().

WIFSIGNALED(s) 

Evaluates to a non-zero value if status was returned for a child process that terminated due to receipt of a signal that was not caught.

WTERMSIG(s) 

If the value of WIFSIGNALED(s) is non-zero, this macro evaluates to the number of the signal that caused the termination of the child process.

WIFCORED(s) 

Evaluates to a non-zero value if status was returned for a child process that terminated due to receipt of a signal that was not caught, and whose default action is to dump core.

WCOREDUMP(s) 

Evaluates to a non-zero value if status was returned for a child process that terminated due to receipt of a signal that was not caught, and whose default action is to dump core.

WCORESIG(s)

If the value of WIFCORED(s) is non-zero, this macro evaluates to the number of the signal that caused the termination of the child process.

WIFSTOPPED(s) 

Evaluates to a non-zero value if status was returned for a child process that is currently stopped.

WSTOPSIG(s) 

If the value of WIFSTOPPED(s) is non-zero, this macro evaluates to the number of the signal that caused the child process to stop.


RETURN VALUES

On success, wait() returns process ID of a child when the status of that child is available. Otherwise, it returns -1 and sets errno to one of the following values:

ECHILD 

The process or process group specified by pid does not exist or is not a child of the calling process.

EFAULT 

stat_loc is not a writable address.

EINTR 

The function was interrupted by a signal. The value of the location pointed to by stat_loc is undefined.


CONFORMANCE

POSIX.1 (1996).


MULTITHREAD SAFETY LEVEL

Async-signal-safe.


PORTING ISSUES

The NuTCRACKER Platform converts the exit status of native Windows applications to UNIX format, which allows wait() to work correctly with either NuTCRACKER Platform or non-NuTCRACKER Platform processes.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
_exit(), _NutForkExecl(), _NutForkExecle(), _NutForkExeclp(), _NutForkExeclpe(), _NutForkExecv(), _NutForkExecvp(), _NutForkExecvpe(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), exit(), fork(), vfork(), waitpid()


PTC MKS Toolkit 10.4 Documentation Build 39.