Free — no signup required

The Lifecycle Part 3: Death and Reporting (`exit` & `wait`)

1 min read

The Responsibility of Parenthood

When a process finishes its work, it calls exit(status), where status is a number: 0 conventionally means success, anything non-zero means an error. This exit code is how processes communicate success or failure to their parents — it's the same value you check with $? in bash after running a command.

But the process doesn't vanish immediately. The kernel keeps a minimal record of it — its PID, exit code, and a few accounting statistics — until the parent acknowledges the death. The parent does this by calling wait() (or waitpid()), which:

  1. Blocks the parent until a child finishes (or returns immediately if one already has).
  2. Retrieves the child's exit status.
  3. Signals the kernel to fully release the child's process table entry.

Only after wait() is called does the child completely cease to exist in the system.

Why this two-step design? The kernel needs somewhere to store the exit code between the child dying and the parent reading it. The process table entry serves as that mailbox. The parent might be busy doing other work and will check the mailbox when ready.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free