Master the fundamental concepts of process management through this focused micro-challenge.
Unix process creation rests on fork(): duplicate the parent, give the child its own PID, and let both resume at the same instruction. The return value is the only immediate clue about which side you are on. Parent gets the child's PID; child gets zero. That split is simple on paper and subtle in real kernels that use copy-on-write pages and careful file-descriptor tables.
A simulator keeps a process table instead of hardware page tables:
For example, if process 1000 calls fork() and receives PID 1001 in the parent branch, the child branch must see return value 0 and getpid() == 1001. Mix those up and your pstree-style output lies.
fork()'s copy-on-write duplication is why Apache's prefork MPM and PostgreSQL's process-per-connection model can spin up workers cheaply, and why a naive fork() in a multi-threaded program can deadlock (the classic post-fork mutex bug glibc's manual warns about). Building the PCB and generation tree by hand shows why chrome://process-internals and pstree display parent-child chains the way they do.
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 the PCB, fork(), wait(), and exit() in userspace so you can watch parent-child lifetimes without invoking the real syscall. This exercise asks you to make the generation counter and zombie reaping explicit, which is the same bookkeeping the kernel hides behind waitpid().
Implement a userspace process simulator that mimics fork() behavior.
Requirements:
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