#include <sys/wait.h>
wait, waitpid, both of them wait for a child process to stop or terminate.
The waitpid() function obtains status information for process termination, and optionally process stop and/or continue, from a specified subset of the child processes.
(on case using wait(), If termination status information is available for two or more child processes, the order in which their status is reported is unspecified.)
wait(stat_loc) = waitpid(pid_t - 1, stat_loc, 0);
pid_t waitpid(pid_t pid, int *stat_loc, int options);
pid
: The pid argument specifies a set of child processes for which status is requested.
The waitpid() function shall only return the status of a child process from below set.
stat_loc
: if the value of the argument stat_loc is not a null pointer, information shall be stored in the location pointed to by stat_loc.
options
: The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags, defined in the <sys/wait.h> header(below).
pid == (pid_t)-1
: status is requested for any child process.
pid > 0
: it specifies the process ID of a single child process for which status is requested.
pid == 0
: status is requested for any child process whose process group ID is equal to that of the calling process.
pid < (pid_t)-1
: status is requested for any child process whose process group ID is equal to the absolute value of pid.
WCONTINUED
: The waitpid() function shall report the status of any continued child process specified by pid whose status has not been reported since it continued from a job control stop.
WNOHANG
: The waitpid() function shall not suspend execution of the calling thread if status is not immediately available for one of the child processes specified by pid.
WUNTRACED
: The status of any child processes specified by pid that are stopped, and whose status has not yet been reported since they stopped, shall also be reported to the requesting process.
: returns a value equal to the process ID of the child process for which status is reported.
using macro func.
note
the cases that value of stat_loc is 0.