Wait, Chapter 26
Objectives
We would like to :
- Investigate the various forms of wait.
Notes
- When a process exits, the parent receives a SIGCHILD
-
pid_t wait (int * _Nullable wstatus)
-
pid_t waitpid(pid_t pid, int * _Nullable wstatus, int options);
- Need sys/wait.h
- Return on exit
- waitpid can wait for
- pid = -1: any child
- > 0 specific PID
- other options for process group, if we discuss that.
- status:
- Pointer to an int.
- Macros
- WIFEXITED(status): true if normal exit.
- WEXITSTATUS(status) : return value
- WIFSIGNALED(status): True if child was killed by a signal
- WTERMSIG(status): Returns signal that caused termination
- WIFSTOPPED(status): true if the child has been stopped.
- WSTOPSIG(status): returns signal that stopped the child.
- WIFCONTINUED(status): True if the child was continued
-
waitpid
can be used to
- Wait for stop and continue signals (WUNTRACED, WCONTINUED)
- Perform a non-blocking check: WNOHANG
- Return
- PID of child exiting or -1 on error.
- Or if non-blocking : 0 on no exit.
- We will deal with signals eventually, but this is one way to handle a child process exit.
-