Lion Cipher Lab

Build a Unix shell with job control: fork, exec, pipes, and signals

Why it matters

You already built a shell that runs commands, but press Ctrl-Z in it and nothing useful happens; type a long pipeline and you cannot push it to the background; there is no `jobs`, no `fg`, no `bg`. Those are not extra features bolted on — they are a whole kernel subsystem your shell has to cooperate with, and it is the part of a shell almost nobody understands until they implement it. Job control is how ONE terminal multiplexes MANY jobs: each pipeline gets its own PROCESS GROUP, the terminal has exactly one FOREGROUND group at a time, and the shell's job is to hand the terminal to a job…

What you'll learn

Steps in this lab

  1. Read this first: your own box, your own programs, an interactive terminal
  2. What job control actually is: process groups, sessions, and the foreground
  3. The shell's side of the deal: ignore the terminal signals, hand off the terminal
  4. Set up a scratch box and initialize the shell
  5. The whole shell: jsh.c (write it now, then we dissect it)
  6. Mechanism 1 — the setpgid race: why the call appears twice
  7. Mechanism 2 — tcsetpgrp: handing over the terminal (and why Ctrl-Z now works)
  8. Mechanism 3 — WUNTRACED and the background poll: stopped is not dead
  9. Break it on purpose #1 — the tcsetpgrp SIGTTOU freeze
  10. Break it on purpose #2 — the SIGCHLD reaping race and orphaned/zombie jobs
  11. The judgment: where your shell sits, and what a real one adds

Open the full interactive lab →