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
- List the components of a process's address space and who owns each region.
- State the five primary process states and the transitions between them.
- State what
fork()duplicates and what it does not. - State what
execve()changes and what it preserves. - Explain in one sentence what copy-on-write does and why it matters for
fork.
Compare and Distinguish
Separate these pairs:
- process versus program
forkversuscloneversusvfork- 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:
- "After
fork(), the child has its own stack, so changes there affect the parent too." - "
fork()always copies the entire parent address space immediately." - "The PCB lives in the process's own memory."
- "A process in the BLOCKED state is using CPU."
- "A zombie is a running process you cannot kill."
- "After
exec, the program counter is wherever it was beforeexecwas 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:
- How many distinct processes exist at peak?
- What does the parent print?
- Why does the
printf("child x=%d\n", x)line never execute? - 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:
- is created
- runs briefly
- issues a
readon a slow disk - completes the read
- gets preempted after its quantum
- 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:
- Timer tick preempts the process.
- Process opens a file.
- Process's parent exits (re-parented to
init). - Process is moved between CPUs by the load balancer.
- Process calls
setuid.
Evidence Check
This page is complete only if:
- You can predict program output from
fork/exec/waitpatterns 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+ immediateexeccheap.