Module 4: Systems-Level Programming: Mistake Clinic
This clinic turns wrong moves into reusable judgment. Use it after each practice page and again before the quiz or checkpoint.
Module-Specific Mistake Radar
Start with these traps. Replace or extend them with real mistakes from your own work.
| Mistake to look for | Where it shows up | Symptom | Repair evidence |
|---|---|---|---|
| Finishing Processes and Pipes Lab with only a final answer | Processes and Pipes Lab | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Finishing File I/O and mmap Workshop with only a final answer | File I/O and mmap Workshop | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Finishing Concurrency and Debugging Clinic with only a final answer | Concurrency and Debugging Clinic | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Finishing Code Katas with only a final answer | Code Katas | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Treating What a Process Is and How Syscalls Cross the Kernel Boundary as vocabulary instead of a tool | What a Process Is and How Syscalls Cross the Kernel Boundary | The explanation names the concept but cannot decide between two cases. | Write one example, one non-example, and the rule that separates them. |
| Treating fork, exec, wait: Creating and Managing Processes as vocabulary instead of a tool | fork, exec, wait: Creating and Managing Processes | The explanation names the concept but cannot decide between two cases. | Write one example, one non-example, and the rule that separates them. |
Practice Mistake Checks
Pull any miss from these checks into your mistake log.
Processes and Pipes Lab
Source: practice/01-processes-and-pipes-lab.md
For each snippet, identify the bug:
- A child calls
exit(1)after a failedexecvp, flushing the parent's stdio buffers twice. - A parent forks
A | B | C, forgets to close all three pipe ends in itself, andCnever sees EOF. - A
SIGINThandler callsprintffrom the main loop's middle. - A program spawns 100 children and never calls
waitpid; the process table fills up. - A
fork/execprogram closes fd 1 in the parent, then opens a file, expecting fd 1 to point at it -- forgetting the child had already inherited the old fd 1.
File I/O and mmap Workshop
Source: practice/02-file-io-and-mmap-workshop.md
- Writing a
catthat assumesread(fd, buf, 4096)always returns 4096 until EOF. - Calling
lseekon a pipe and treating theESPIPEerror as "the file is weird." - Calling
open(path, O_CREAT | O_WRONLY)without amode_t, getting random-garbage permissions. mmap-ing a 10 GB file and assuming RSS will be 10 GB.- Modifying a
MAP_PRIVATE | PROT_WRITEmapping and expecting the file on disk to change.
Concurrency and Debugging Clinic
Source: practice/03-concurrency-and-debugging-clinic.md
- Writing
if (empty) cond_wait(...)instead ofwhile (empty) cond_wait(...). - Using
volatile int doneas a cross-thread stop flag and then wondering why the worker loops forever. - Signalling a condition variable after unlocking the mutex, and losing the wake-up.
- Passing
&localtopthread_createand returning from the enclosing function before the thread reads it. - Attempting to debug an
-O3build withgdband being surprised that half the locals are "value optimized out."
Repair Protocol
For each real mistake:
- Reproduce the failure on the smallest example, trace, proof, query, command, or design sketch.
- Name the hidden assumption.
- Repair the artifact.
- Save evidence that changed: failing then passing test, corrected proof step, revised diagram, safer command, benchmark, or review note.
- Add one retrieval card beginning with Check... before... or Do not use... when....
Mistake Log
| Date | Mistake | Symptom | Root cause | Repair evidence | Retrieval card |
|---|---|---|---|---|---|
| Starter | Pick one radar row above | Explain how it would fail in this module | Name the assumption | Add a counterexample or corrected artifact | Write the card before closing the page |
Completion Standard
- At least five real mistakes are logged.
- At least two mistakes include a counterexample or failing test.
- At least one mistake connects to an older semester skill.
- At least one correction changes code, a proof, a diagram, a command transcript, a query, or a design decision.