Skip to main content

Book Exercise Lanes

This module's exercise system is book-driven and man-page-driven. Use these local chunks, canonical Linux man pages, and your own keyboard for targeted volume after you have already learned the concept from the guide.

How To Use This Page

  1. Finish the relevant concept page first.
  2. Solve at least one exercise from memory on your own machine.
  3. Only then open the matching book chunk or man page.
  4. Keep a mistake log with tags such as partial read not looped, forgot to close FD in parent, used exit in child after failed exec, mutex not held when signalling, endianness forgotten in sockaddr_in, or debug build measured as production.

Lane 1: Raw I/O from K&R Chapter 8

Use this lane when your read/write loops are not yet reflexive.

Local chunks:

Target outcomes:

  • implement cat and wc -l using only open/read/write/close
  • transcribe K&R's _fillbuf/getc and test it against the system versions
  • write a minimal ls that reads a directory with getdents64 (or readdir) and prints names

Book-chunk exercises: K&R Exercises 8-1, 8-2, 8-3, 8-4 (re-implement cat with raw syscalls, implement a stripped fopen). Solve from memory before looking at the chunk.


Lane 2: Processes, Signals, and Pipes

Use this lane when fork/exec/wait is not yet automatic.

Local chunks:

Man pages:

External:

Target outcomes:

  • 5 variants of fork + exec + wait (with/without argv, with environment change, with fd redirection)
  • a mini shell with single-stage and two-stage pipelines
  • a SIGINT + SIGTERM handler program that sets a flag and shuts down cleanly
  • a reaper that handles SIGCHLD with a waitpid(-1, ..., WNOHANG) loop

Lane 3: mmap, Shared Memory, Allocators

Use this lane when memory mapping and custom allocation are abstract rather than mechanical.

Local chunks:

Man pages:

External:

Target outcomes:

  • a memory-mapped word counter that beats read-based wc on a 1 GB file
  • a MAP_SHARED two-process counter with correct atomics
  • a full transcription of the K&R free-list allocator with your own tests
  • a bump arena API used in at least one small parser project

Lane 4: Concurrency Primitives

Use this lane when pthread programs are not yet reliably correct.

Local chunks:

Man pages:

External:

Target outcomes:

  • a producer-consumer with N producers and M consumers that produces the same result on 50 consecutive runs
  • a race diagnostic note that correctly names every race in a 50-line multithreaded program
  • an atomic_int counter benchmarked against a mutex-protected counter at 1, 2, 4, 8 threads
  • a helgrind or tsan clean build of one small concurrent program

Lane 5: Sockets and Debugging

Use this lane when networking or debugging is still intimidating.

Man pages:

External:

Target outcomes:

  • a TCP echo server and client, written from memory
  • a tiny HTTP server that serves 1,000 requests without leaking fds
  • a gdb session transcript for a planted bug (breakpoint + watchpoint + bt)
  • an strace -c annotation for a slow program identifying the dominant syscall
  • a valgrind clean build of a small program with at least three allocations