fork, exec, and the Process Model
fork() duplicates the calling process — the child gets a copy of the parent’s memory, file descriptors, and execution state. Returns 0 in the child, the child’s PID in the parent. exec() family replaces the current process image with a new program — same PID, new code. The fork + exec pattern is how shells launch programs. wait()/waitpid() lets the parent collect the child’s exit status (prevents zombies). Copy-on-write optimization means fork() is cheap — pages are shared until one process writes.