$_ CLI In Depth
Learning progress 0%
lesson processes signals job-control

Signals & kill

5 min read Module 10: Processes, Signals & Job Control Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:24

What a signal is

A signal is a small integer that the kernel delivers to a process at any time. The process can be running, sleeping, or stopped when the signal arrives. The kernel does not send the whole message, only the number. Each signal has a default action, such as terminate, ignore, stop, or continue. A process can change some of those actions with a handler, and it can block some signals so they wait in a queue until it unblocks them.

Signals are the mechanism behind several keys you already know. Ctrl-C sends SIGINT, Ctrl-Z sends SIGTSTP, and Ctrl-\ sends SIGQUIT. The terminal line discipline generates those signals for the foreground process group, as described in the terminal lesson earlier in this course.

Listing the signal names

The kill builtin in bash can list every signal name with its number. The -l option prints the list, and when you give it a number it prints the name for that number. Some signals have the same number on every Linux system, while others vary by architecture, so use the list on your system when a number matters.

BASH3 lines
kill -l
kill -l 15
kill -l 9

The first command prints the whole table on one set of lines. The second prints TERM, because signal 15 is SIGTERM. The third prints KILL, because signal 9 is SIGKILL. The most common signals are HUP (1), INT (2), QUIT (3), KILL (9), USR1 (10), USR2 (12), TERM (15), CONT (18), STOP (19), and TSTP (20) on Linux.

Sending a signal

The kill command takes a signal, then one or more PIDs. You can name the signal by number, as in kill -9 PID, or by name with or without the SIG prefix, as in kill -TERM PID. Without a signal option, kill sends SIGTERM. A program that receives SIGTERM is expected to clean up and exit, so it is the polite first choice.

The following block sends a user signal to the shell itself, after installing a trap that prints a message when the signal arrives.

BASH3 lines
trap "echo got USR1" USR1
kill -USR1 $$
echo back in the shell

The trap runs as soon as the shell handles the signal. The message appears before the final echo, because the signal is delivered to the shell at the next safe point. The shell continues afterward, which shows that a handled signal does not end the process.

SIGKILL and SIGTERM

SIGKILL cannot be caught, blocked, or ignored. The kernel terminates the process directly, and the process gets no chance to flush files or remove temporary data. SIGTERM is different: it can be handled, so a program can save state before it exits. For that reason you should send SIGTERM first and use SIGKILL only when a process does not respond.

SIGSTOP is the stop signal that also cannot be caught, and SIGCONT resumes a stopped process. Ctrl-Z is the interactive version of SIGTSTP, which a program can catch, while SIGSTOP always stops the process.

Warning

Do not send SIGKILL to a process unless SIGTERM has failed. The process cannot clean up, so it may leave lock files or half-written data behind.

The exit status after a signal

When a process is killed by a signal, the shell does not see a normal exit code. It reports 128 plus the signal number in $?. A program that ends with SIGTERM therefore shows 143, and one that ends with SIGINT shows 130. The kill -l command understands this convention, so you can convert the status back into a name.

BASH2 lines
kill -l 143
kill -l 130

These commands print TERM and INT. The arithmetic is 143 minus 128, which is 15, and 130 minus 128, which is 2. This is the same convention that the first lesson of the course used for Ctrl-C.

Signals also explain a common surprise with scripts. A script that traps SIGTERM to clean up will not exit when it receives the signal until its handler returns, and a long command inside the handler delays the exit. This is why a handler should do the minimum, set a flag, and let the main loop check the flag. The kernel does not wait for the handler, so the signal is delivered at once, but the work still has to finish before the process can end.

Finally, remember that a signal goes to a process, not to a command line. If a pipeline has three stages, a signal sent to one PID affects only that stage, and the others keep running until their input ends. To stop the whole pipeline, send the signal to every stage or to the process group. The job control lesson that follows shows how the shell groups the stages of a pipeline together so that a single Ctrl-C reaches all of them.

Hands-on: send and observe

Start a background sleep, record its PID in a file, and send it SIGTERM. The sleep does not catch the signal, so it stops at once. The lesson is in the status: the job ends by signal, not by normal completion.

BASH3 lines
sleep 300 & echo $! > job.pid
kill -TERM "$(cat job.pid)"
wait "$(cat job.pid)"; echo "status $?"

The final status is 143, because the sleep ended with SIGTERM. Run kill -l 143 to see the name. The PID you record in the file changes each time, which is why the lab check reads the file rather than expecting a fixed number.

Signals, job control and hangups

Visualizer

A signal is a small numbered message the kernel delivers to a process. Some signals can be caught and some cannot. Job control and SIGHUP decide which signals a job gets.

1 / 5
Linux signal numbers (the same on this aarch64 machine)
SignalNo.Default actionCan a program catch it?
SIGHUP1terminateyes
SIGINT2terminateyes
SIGKILL9terminateno
SIGTERM15terminateyes
SIGCONT18continueyes
SIGSTOP19stopno
SIGTSTP20stopyes

The default action is what the kernel does when a program installs no handler. SIGKILL and SIGSTOP can never be caught or ignored.

sleep 30 & p=$!; kill -TERM $p; wait $p; echo "status $?"
Terminal lab · 2 steps · real Linux in your browser

Name signals and terminate a job

Convert signal numbers to names, then send SIGTERM and read the status it leaves behind.

01
Convert signal numbers to names
The kill builtin with -l turns a signal number into its name. Save the name for number 15 and then the name for number 9 in sig.txt. ``bash kill -l 15 > sig.txt kill -l 9 >> sig.txt `` The file should contain two lines: TERM and KILL.
Show hint for step 1
Use kill -l with the number, and use > for the first line and >> for the second.
02
Send SIGTERM and read the status
Start a background sleep and record its PID in job.pid. Send it SIGTERM with kill, wait for it, and save the status in killed.txt in the form status=N. ``bash sleep 300 & echo $! > job.pid kill -TERM "$(cat job.pid)" wait "$(cat job.pid)"; echo "status=$?" > killed.txt `` A process ended by SIGTERM reports 128 plus 15, which is 143.
Show hint for step 2
The status must be read by wait right after the kill. A plain kill with no signal name also sends SIGTERM.
Check yourself Question 1 of 4
Concept Check Uncatchable signal recall

Which signal cannot be caught, blocked, or ignored by a process?

Recap & Key Takeaways

A signal is a small number the kernel delivers to a process, and the default action depends on the signal.
kill sends SIGTERM by default, and SIGKILL cannot be caught, blocked, or ignored, so use it only when SIGTERM fails.
A process killed by a signal reports 128 plus the signal number in $?, so SIGTERM shows as 143 and SIGINT as 130.
The kill -l command lists signal names, and kill -l with a number converts a number or an exit status back to a name.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue