Wait for the status of a terminated child process
#include <sys/types.h> #include <sys/wait.h> pid_t wait( int * stat_loc );
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The wait() function suspends execution of the calling thread until status information from one of its terminated child processes is available, or until the delivery of a signal whose action is either to terminate the process or execute a signal handler. If status information is available prior to the call to wait(), the return is immediate.
If the stat_loc variable is non-NULL, the terminating status of the child process is in the location that it points to. The macros listed below, defined in <sys/wait.h>, extract information from stat_loc. The stat_val argument to these macros is the integer value pointed to by stat_loc.
POSIX defines the following macros:
This macro isn't part of a POSIX standard:
One of the macros WIFEXITED(*stat_loc) and WIFSIGNALED(*stat_loc) evaluates to a nonzero value.
The non-POSIX waitid() function gives even more status information than the above macros.
The process ID of the terminating child process, or -1 if an error occurred or on delivery of a signal (errno is set to EINTR).
errno, spawn(), wait4(), waitid(), waitpid()