Skip to main content

Process Model Workshop

A workshop for making the process abstraction and its lifecycle operational -- what a process actually consists of, how it is created, and how kernel state represents it.

Retrieval Prompts

  1. List the components of a process's address space and who owns each region.
  2. State the five primary process states and the transitions between them.
  3. State what fork() duplicates and what it does not.
  4. State what execve() changes and what it preserves.
  5. Explain in one sentence what copy-on-write does and why it matters for fork.

Compare and Distinguish

Separate these pairs:

  • process versus program
  • fork versus clone versus vfork
  • parent PID versus process group ID versus session ID
  • READY versus RUNNING versus BLOCKED
  • ZOMBIE versus orphan
  • user mode versus kernel mode
  • the PCB versus the address space

Common Mistake Check

Identify the error:

  1. "After fork(), the child has its own stack, so changes there affect the parent too."
  2. "fork() always copies the entire parent address space immediately."
  3. "The PCB lives in the process's own memory."
  4. "A process in the BLOCKED state is using CPU."
  5. "A zombie is a running process you cannot kill."
  6. "After exec, the program counter is wherever it was before exec was called."

Mini Application

Trace fork/exec by hand

Hand-simulate the following program: for each step, state what the state is in each process (PC, variable x, the value of getpid()), and what gets printed.

int x = 10;
pid_t p = fork();
if (p == 0) {
x = 20;
execve("/bin/echo", (char*[]){"echo","child", NULL}, envp);
printf("child x=%d\n", x);
} else {
waitpid(p, NULL, 0);
printf("parent x=%d\n", x);
}

Answer:

  1. How many distinct processes exist at peak?
  2. What does the parent print?
  3. Why does the printf("child x=%d\n", x) line never execute?
  4. Which fields in the child's PCB get reset by the execve, and which are preserved?

Draw state transitions

Draw a state diagram for a process that:

  1. is created
  2. runs briefly
  3. issues a read on a slow disk
  4. completes the read
  5. gets preempted after its quantum
  6. exits

Label each transition with who causes it (the scheduler, an interrupt, the process itself, the parent).

PCB field pass

For each scenario, name the PCB field(s) that change:

  1. Timer tick preempts the process.
  2. Process opens a file.
  3. Process's parent exits (re-parented to init).
  4. Process is moved between CPUs by the load balancer.
  5. Process calls setuid.

Evidence Check

This page is complete only if:

  • You can predict program output from fork/exec/wait patterns without running the code.
  • You can draw the 5-state process state diagram from memory with all transitions.
  • You can name which PCB fields change on each of the common transitions (tick, I/O wait, exec, exit).
  • You can explain copy-on-write and why it makes fork + immediate exec cheap.