Birth and death of a process: zombies, orphans and PID 1

The kernel and the programs it runs. This lesson follows one program from the moment it is made to the moment the kernel finally forgets it.
On 20 January 2015, Hongli Lai of the company Phusion published a post called “Docker and the PID 1 zombie reaping problem”. His example was a web server in a container. It runs a small script, and the script runs a search program. The server stops the script after a timeout, but the search program keeps going. When it finishes, nobody collects its result. It stays in the system as a dead entry that never leaves. Do that thousands of times and the machine cannot start any new program.
Nothing crashed and no error was shown. A program ended, and the system waited for someone to say “I have seen that it ended”.
By the end you will be able to follow any process from birth to death, say who must act at each step, and explain why PID 1 has a job that no other process has.
The history (optional)
Phusion’s post said that Docker did not run containers under an init program that waits for adopted children, so a container’s first program had to do it. Docker 1.13 added the --init option, which puts a small program called tini in as PID 1, as Linux and the Shell: Processes, Files, Pipes, Permissions and Signals shows.
The Linux manual says the call that lets an ordinary program adopt orphans, PR_SET_CHILD_SUBREAPER, has existed since Linux 3.4. The second read uses it.
Before you start. The kernel is the one program that makes processes, and each process has its own id number (Processes, Threads & the Kernel). A shell makes a child with fork, replaces the child with a new program using exec, and then waits for it (The program that starts programs). The first process of a machine is PID 1, which the boot chain starts last (From power button to PID 1: how a machine boots). A first look at a zombie came when signals were introduced (The tap on the shoulder). This lesson follows the whole life.