Waits for a child process to terminate.
#include <sys/wait.h> pid_t wait ( int *stat_loc);
(OUT) Points to where the status information of the child process is returned. If a NULL pointer is passed, status information is not returned.
When the status of a child process is available, returns the pid of the process.
If wait returns because of an error or because the calling thread was interrupted, returns -1 and sets errno to one of the following:
The stat_loc parameter returns 0 if the child process terminated by one of the following methods:
The process returned 0 from main.
The process called _exit or exit with a status argument of 0.
The process terminated because the last thread of the process terminated.
The following two macros can be used to evaluate the stat_loc value. The status parameter is the value returned in stat_loc.
Evaluates to a nonzero value if status indicates that the child process terminated normally.
If the value of WEXITSTATUS (status) is nonzero, the macro evaluates to the low-order 8 bits of the status argument which the child process passed to _exit or exit or the value the child process returned from main.