In our simpsh program, we did use the wait(2) API, but have not really delved into details:
pid_t wait(int *wstatus);
The thing to understand is this: wait(2) is a blocking call; it causes the calling process to block until a child process dies.
To be technically correct, the wait(2) (and associated APIs that we shall see later) actually block upon the child process(es) undergoing a state change; well, the state change is the child's death, right? Yes, but it's really important to understand that it's not just that: the possible state changes are as follows:
- The child process terminates as follows:
- Normally (by falling off main, or calling [_]exit())
- Abnormally (killed by a signal).
- The child was sent a signal ...