Master the fundamental concepts of process management through this focused micro-challenge.
When a child calls exit(), it becomes a zombie until the parent collects its status with wait() or waitpid(). The kernel keeps a minimal PCB skeleton so the parent can read the exit code. Ignore reaping and PIDs leak until the process table fills.
Both syscalls block until a child changes state:
WNOHANG pollsStatus encoding packs signal and exit code. On Linux, WIFEXITED(status) and WEXITSTATUS(status) decode the bits. For example, child exiting with code 3 leaves a status word whose low byte is 3 when exited normally.
Forgetting to reap zombies is a real production failure mode: Docker containers running a shell script as PID 1 famously accumulate zombies until the process table fills, which is why tini and dumb-init exist solely to call wait() on behalf of orphaned children. The WIFEXITED/WEXITSTATUS bit-packing you implement here is exactly the encoding bash's $? and git's exit-code checks rely on.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will implement blocking wait loops, zombie marking on exit, and status propagation to the parent. This task asks you to handle multiple children and show why shell pipelines depend on implicit reaping of background jobs.
Implement wait() and waitpid() system calls for process reaping.
Requirements:
Test scenarios:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github