The wait API – details

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 ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.