wait and reaping a child
/ reaping, 'REE-ping' /
Imagine a parent who sent a child to run an errand. When the child returns, the parent listens to the report, signs off, and only then is the errand truly closed. In the process world, this is wait and reaping: the parent uses the wait system call to pause until a child finishes, then collects the child's exit status, and that act of collection lets the OS finally remove the finished child.
When a parent calls wait (or waitpid for a specific child), the OS does two things. If the child is still running, the parent blocks until it terminates. Once the child has terminated, wait returns the child's exit status to the parent and then the OS deletes the child's remaining bookkeeping, its PCB and process-table entry. That second step is the reaping: collecting the status and clearing the slot. Without it, the terminated child cannot be fully removed, because the OS must keep its exit status around until someone reads it. A parent that creates several children should wait for each one.
Reaping matters for two reasons: it is how a parent learns how its child fared (success, failure, killed by a signal), and it is how the system avoids accumulating zombies. A common beginner bug is forgetting to wait, which leaves a growing pile of zombie children that waste process-table entries. There is a useful subtlety: a parent can be notified when a child dies (via the SIGCHLD signal) and reap it then, rather than blocking; and if a parent exits without reaping, the orphaned (now also terminated) children are inherited by init, which reaps them, so they do not stay zombies forever.
After forking a child, the parent calls wait(&status). It blocks until the child exits, then status holds the child's exit code and the child's process-table slot is freed; the child is now fully gone.
wait blocks until the child exits, returns its status, and reaps it.
Reaping is required, not optional. A parent that never waits leaves zombie children that consume process-table entries until the parent exits and init reaps them.