A shell of your own

: the kernel and the programs it runs. You will write the program in the middle of that picture, the one that starts the other programs and decides which of them the keyboard talks to.
You type sleep 30 | cat and change your mind. You press Ctrl-C. Two programs die, and your shell stays alive and shows a new prompt. Here is a real run of the shell built in this lesson, on Linux 7.0.0 with Python 3.12.3 on 2026-11-28:
$ sleep 30 | cat
^C[1] killed by signal 2
$ echo alive
alive
One key press reached two programs at once and skipped the third, the shell itself. Nobody wrote “kill these two but not me” anywhere in sleep or cat. The shell arranged it before they started. Try Ctrl-Z instead and the same two programs freeze, the shell takes back the keyboard, and one word, fg, wakes them.
By the end you will be able to write a shell of about 120 lines that parses pipelines and redirects, runs each one as a group the terminal can address, and supports Ctrl-C, Ctrl-Z, &, jobs, fg and bg.
The history (optional)
The C shell’s own introduction says that Jim Kulp added the job control and directory stack primitives to it. A discussion on the Unix history mailing list says Kulp did this at IIASA, an institute in Austria, that he did the signal work in the kernel and the shell code, and that Bill Joy folded it into 4.1BSD. A 4.2BSD job control paper by David Lennert of HP says Kulp’s design became a de facto industry standard. Before it, a terminal ran one program at a time and you waited for it.
Before you start. A shell is a loop that forks a child, replaces it with the command (exec) and waits, and a pipe is a one-way channel whose reader sees end of input only after every copy of the writing end is closed (The program that starts programs). A signal is a small numbered note the kernel delivers to a process, and Ctrl-C makes one (The tap on the shoulder). A child that ends keeps its exit status until its parent calls wait (Birth and death of a process: zombies, orphans and PID 1). Every process holds numbered doors called file descriptors (Everything is a file descriptor). The earlier shell ignored Ctrl-C. This one fixes the cause.