Skip to main content

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 forWhere it shows upSymptomRepair evidence
Finishing Processes and Pipes Lab with only a final answerProcesses and Pipes LabThe 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 answerFile I/O and mmap WorkshopThe 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 answerConcurrency and Debugging ClinicThe 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 answerCode KatasThe 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 toolWhat a Process Is and How Syscalls Cross the Kernel BoundaryThe 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 toolfork, exec, wait: Creating and Managing ProcessesThe 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:

  1. A child calls exit(1) after a failed execvp, flushing the parent's stdio buffers twice.
  2. A parent forks A | B | C, forgets to close all three pipe ends in itself, and C never sees EOF.
  3. A SIGINT handler calls printf from the main loop's middle.
  4. A program spawns 100 children and never calls waitpid; the process table fills up.
  5. A fork/exec program 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

  1. Writing a cat that assumes read(fd, buf, 4096) always returns 4096 until EOF.
  2. Calling lseek on a pipe and treating the ESPIPE error as "the file is weird."
  3. Calling open(path, O_CREAT | O_WRONLY) without a mode_t, getting random-garbage permissions.
  4. mmap-ing a 10 GB file and assuming RSS will be 10 GB.
  5. Modifying a MAP_PRIVATE | PROT_WRITE mapping and expecting the file on disk to change.

Concurrency and Debugging Clinic

Source: practice/03-concurrency-and-debugging-clinic.md

  1. Writing if (empty) cond_wait(...) instead of while (empty) cond_wait(...).
  2. Using volatile int done as a cross-thread stop flag and then wondering why the worker loops forever.
  3. Signalling a condition variable after unlocking the mutex, and losing the wake-up.
  4. Passing &local to pthread_create and returning from the enclosing function before the thread reads it.
  5. Attempting to debug an -O3 build with gdb and being surprised that half the locals are "value optimized out."

Repair Protocol

For each real mistake:

  1. Reproduce the failure on the smallest example, trace, proof, query, command, or design sketch.
  2. Name the hidden assumption.
  3. Repair the artifact.
  4. Save evidence that changed: failing then passing test, corrected proof step, revised diagram, safer command, benchmark, or review note.
  5. Add one retrieval card beginning with Check... before... or Do not use... when....

Mistake Log

DateMistakeSymptomRoot causeRepair evidenceRetrieval card
StarterPick one radar row aboveExplain how it would fail in this moduleName the assumptionAdd a counterexample or corrected artifactWrite 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.