user space$ python3 worker.py &[1] 4242$ kill 4242cleaning up[1]+ Done python3 worker.pybash · 12001import signal, time2def bye(signum, frame):3 print("cleaning up")4 raise SystemExit(0)5signal.signal(signal.SIGTERM, bye)6time.sleep(300)python3 · PID 4242Linux kernel2SIGINT15SIGTERM9SIGKILLbashpython3PID1200PPID1100STATSpending—PID—PPID—STAT—pending—python3 worker.py &kill 4242kill -9 4242159cleaning upexit 0status 0
Back: user space (terminal, shell, worker.py and its process). Front: the Linux kernelProcess table: one row per process (PID, parent PID, state, pending signal)Tokens: your command, a start signal, signals (15, 9) and the exit statusUser space at the back: the terminal, the shell (bash, PID 1200), the program worker.py and, once it runs, its process (PID 4242). The Linux kernel in front, with three common signals and two rows of the process table. The shell starts the program through the kernel; kill asks the kernel to send SIGTERM, the program's handler cleans up and exits, its row turns into a zombie until bash collects it. SIGKILL ends a process without running its handler. The PIDs (1200 for bash, 1100 for its parent, 4242 for the program) are examples. Your machine picks its own.

What a process is

  1. A process is a program that is running. The kernel gives each process a number, its PID, and keeps a row about it in the process table. Your shell, bash, is a process too: here its PID is 1200.

Starting a process

Signals

Ending

What happens

;; step 1/11 · process
process   a program that is running:
          its code, its memory, its open files
PID       the process ID, a number the kernel gives it
process table   the kernel's list: one row per process
  bash   PID 1200   parent 1100   state S
see yours:  echo $$     (the shell's own PID)
            ps -o pid,ppid,stat,comm

The PIDs (1200 for bash, 1100 for its parent, 4242 for the program) are examples. Your machine picks its own. The terminal card is tidied. In a real terminal "cleaning up" may appear just after a new $ prompt, and bash prints the Done line the next time it shows a prompt (press Enter), or at once after set -b. Bash also pads the line with more spaces.