Performing the wait

The wait(2) API is a classic example of a blocking call: The calling process is put into a sleep state until the event it is waiting (or blocking) upon occurs. When the event does occur, it is woken up and continues to run.

So, think about it: a process forks; the parent process then issues the wait (2)API, and the event it is blocking upon is the death of the child! The child continues to run, of course; when the child does die, the kernel wakes up, or unblocks, the parent; it now continues to execute its code. Here is the signature of wait(2):

#include <sys/types.h>#include <sys/wait.h>pid_t wait(int *wstatus);

For now, we shall ignore the to wait(2); we shall just pass NULL (or 0) (of course, we shall cover it shortly). ...

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.