CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 1 of 6 · 1 min read

Why this page comes third

In this module you will

  • Write a C program that creates a child with fork and tells parent from child by the return value.
  • Replace a child's program with exec and explain why the program after a successful exec never runs again.
  • Use wait or waitpid to collect a child and read its exit status.
  • Count the processes made by a program with several fork calls.
  • Explain why output sometimes appears more than once when a program forks.

Page 1 defined a process and page 2 gave its states. This page shows how a process comes to exist at all. On Unix and Linux the answer is a pair of calls, fork to copy and exec to change the program, and a third call, wait, to collect the result. Page 4 uses all three to build a shell, and page 8 shows what happens when wait is skipped. The main sources are "Operating Systems: Three Easy Pieces" (OSTEP), chapter 5, "The Linux Programming Interface" (TLPI), chapters 24 to 28, and "Operating System Concepts" (OSC), chapter 3.

About this example About this example

Real: The C programs, commands and outputs on this page were compiled with gcc -Wall -Wextra -pthread and run on a Linux test machine (2 processors, kernel 6.18, glibc 2.39).

Scripted: The worked traces use small numbers chosen so they can be followed by hand.

Not real: The page simplifies real systems. Actual kernels add more cases, limits and tuning than a short page can show.