<aside> ๐งญ
Module 04 ยท Signals, sessions and job control
Module 02 gave you two signals as a working minimum: TERM to ask politely, KILL to force it. This module covers the rest โ what a signal actually is, why two of them cannot be refused, what Ctrl-C really does, and why closing a terminal sometimes kills your job and sometimes does not.
๐ง concept โ ๐งฉ real-world analogy โ ๐งช exercise โ โ expected result (hidden) โ ๐ฏ interview questions (hidden)
</aside>
<aside> โ
Before you start, you should already know:
From Module 01 โ the user space / kernel boundary, what a system call is, and how to read /proc.
From Module 02 โ PIDs and the process tree, fork and exec, exit status and the 128 + N rule, process states including D.
From Module 03 โ file descriptors, and that descriptors 0, 1 and 2 normally point at your terminal.
</aside>
<aside> ๐
Official docs: signal(7) โ overview of signals ยท proc_pid_status(5) ยท intro(2)
</aside>
A signal is the simplest way one part of the system can interrupt a process. It is worth being precise about how little it is:
A signal is a number. That is the entire message.
There is no text, no payload, no sender's address, and no way to reply. Signal 15 arrives and the process knows only that signal 15 arrived. Everything else โ what it means, what to do about it โ is convention.
Mechanically, delivering a signal is not a message being passed anywhere. The kernel just sets a bit in the target process's record โ the record you met in Module 02. Signal 15 pending? Set the bit for signal 15. (In the masks you will read later, signal N is bit Nโ1, so that is bit 14.)
Then nothing happens until that process next runs. This becomes important in Section A5.
<aside> ๐งฉ
Real-world analogy โ a doorbell with thirty different chimes
You fit a doorbell that can play thirty different tunes. Everyone in the neighbourhood agrees what each tune means. One means "post has arrived". One means "the building is on fire". One means "pause what you are doing".
Now notice how little the doorbell gives you:
That is why signals are used for short, blunt instructions โ stop, pause, reload your config โ and never for passing data. Anything richer needs a different mechanism.
And the meanings are agreed convention, not physics. There is nothing about the number 15 that means "please shut down". Everyone simply agreed.
Where the analogy stops working โ and it is Section A5. A doorbell rings whether or not you are home.
A signal is more like a light that comes on above your door. It stays on until you come out and look. If you are shut in a room that cannot be interrupted, the light can stay on forever and you will never see it.
</aside>
๐งช Exercise A1.1 โ See the whole list
# Every signal this system has, with its number
kill -l
# How many NAMES are listed? (kill -l prints a number and a name for each)
kill -l | wc -w
# The ones you will actually meet, by number
for n in 1 2 3 9 15 17 18 19; do
printf "%3s = %s\n" "$n" "$(kill -l $n)"
done
<aside> ๐
Official docs: signal(7) โ the standard signals table ยท kill(1) ยท termios(3)
</aside>
There are 31 standard signals. You will genuinely use about ten. Here they are, grouped by why they turn up.