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
- Finish the relevant concept page first.
- Solve at least one exercise from memory on your own machine.
- Only then open the matching book chunk or man page.
- Keep a mistake log with tags such as
partial read not looped,forgot to close FD in parent,usedexitin child after failed exec,mutex not held when signalling,endianness forgotten in sockaddr_in, ordebug 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:
- K&R 8.1: File Descriptors
- K&R 8.2: Low-Level I/O -- Read and Write
- K&R 8.3:
open,creat,close,unlink - K&R 8.5: Implementation of fopen and getc
- K&R 8.6: Listing Directories
Target outcomes:
- implement
catandwc -lusing onlyopen/read/write/close - transcribe K&R's
_fillbuf/getcand test it against the system versions - write a minimal
lsthat reads a directory withgetdents64(orreaddir) 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:
- Code: The Operating System (Parts 1-4) -- background picture.
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+SIGTERMhandler program that sets a flag and shuts down cleanly - a reaper that handles
SIGCHLDwith awaitpid(-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:
- COD 5.4: Virtual Memory (Part 1-4) -- hardware model.
- K&R 8.7: A Storage Allocator -- free list.
Man pages:
External:
Target outcomes:
- a memory-mapped word counter that beats
read-basedwcon a 1 GB file - a
MAP_SHAREDtwo-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_intcounter benchmarked against a mutex-protected counter at 1, 2, 4, 8 threads - a
helgrindortsanclean build of one small concurrent program
Lane 5: Sockets and Debugging
Use this lane when networking or debugging is still intimidating.
Man pages:
External:
- Beej's Guide to Network Programming
- GDB User Manual
- Brendan Gregg: Linux perf Examples
- Valgrind User Manual
Target outcomes:
- a TCP echo server and client, written from memory
- a tiny HTTP server that serves 1,000 requests without leaking fds
- a
gdbsession transcript for a planted bug (breakpoint + watchpoint + bt) - an
strace -cannotation for a slow program identifying the dominant syscall - a
valgrindclean build of a small program with at least three allocations