Consider this scenario: A process forks (creates) two children; let's call the parent process P and the children C1 and C2. Recall fork rule #3—the parent and the children processes will all continue to run in parallel. Now, P calls wait; what will happen?
This is the answer: process P will remain blocked until one of the children dies (or stops), but which one? Any one; whichever one changes state first. So how will the systems programmer know which process dies or stopped? That's easy: The return value is the PID of the process that died or stopped.
In other words, we devise a corollary: a wait blocks on a single child process; to block on n children requires n waits.
An interesting exercise would be to construct the preceding ...