Wait
- A parent process is notified when a child process terminates.
- The easiest way to do this is via the wait call.
- Needs sys/wait.h
- pid_t wait(int *stat_loc);
- returns the id of the process that exited, or -1 on error.
- stat_loc contains information about the exit status.
- sys/wait.h contains a number of macros to interpret the exit status.
- WIFEXITED(stat_val) returns true if the child called exit.
- WEXITSTATUS(stat_val) should be used only if the previous was ture, returns the lower 8 bits of the exit status.
- WIFSIGNALED(stat_val) returns true if the child was terminated by a signal
- WTERMSIG(stat_val) should be used only if the previous is true, returns the signal that caused termination.
- WIFSTOPPED(stat_val) returns true if the child was stopped. This is only for waitpid.
- WSTOPSIG(stat_val) returns the signal that stopped the child
- WIFCONTINUED(stat_val) returns true when the child was continued. Again, only for waitpid.
- Wait can return immediately if a child has met the conditions
- Or it can block until this occurs.
- See simpleWait.C
- See multiWait.C
- waitpid
- pid_t waitpid(pid_t pid, int *stat_loc, int options);
- pid:
- the process to wait for if positive
- Or -1 means the next child to exit.
- Or less than -1 means a process in the process group.
- stat_loc as before
- options
- WCONTINUED reports status of continued children
- WNOHANG waitpid is not blocking
- WUNTRACED get stopped children as well.
- See workingWait.C