Goal
Write a working interactive shell that runs external commands, wires pipelines, redirects
I/O, and handles signals and background jobs. Building it turns the process model from
theory into reflex: fork/exec/wait, file descriptors and dup2, process groups,
and the signal-handling that makes Ctrl-C and job control work.
Subject: full brief & instructions
Practices
- Linux system deep dive — fork/exec, process states, signals, and file descriptors are exactly what this exercises.
- Concurrency and parallelism — processes, pipes, and waiting are concurrency at the OS level.
- Networking fundamentals — the same
fd/
epollmachinery underlies socket servers.
Milestones
- REPL + external commands. Read a line, tokenize it,
fork+execvpthe command, andwaitpidfor it. Handle the empty line and a not-found command cleanly. - Built-ins. Implement
cd,exit, andpwd— the ones that must run in the shell process itself (a forkedcdchanges nothing), which teaches why the distinction exists. - Redirection. Parse
>,>>,<and rewire stdin/stdout withopen+dup2beforeexec; confirm the child inherits the redirected descriptors. - Pipelines. Support
a | b | c: createpipes, fork each stage, wire read/write ends withdup2, close unused fds (the leaked-fd bug is a rite of passage), and wait on all. - Signals & job control. Handle
SIGINT/SIGTSTPso they hit the foreground job not the shell; add&background execution, process groups, and ajobslisting.
Stretch goals
- Add environment-variable expansion, globbing, and quoting rules.
- Add command history and line editing (readline or a raw-mode implementation).
Related
- Build your own shell — subject — the full feature spec and acceptance checks for this exercise.
- Linux system deep dive — cites this exercise
in its
# Practicesection. - Write Yourself a Git — the other "build the tool you use daily" systems exercise.