← Linux and the Command Line
Lesson 28 of 51 · 10 XP
Signals: kill
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
A process can be sent a signal — a short message from the system:
| signal | number | meaning |
|---|---|---|
SIGTERM |
15 | "please finish" (the default for kill) |
SIGKILL |
9 | kill immediately; it can't be caught |
SIGINT |
2 | what Ctrl+C sends |
SIGHUP |
1 | "reread your settings" (for many servers) |
SIGSTOP / SIGCONT |
freeze / continue (Ctrl+Z — SIGTSTP) |
kill 1234 # SIGTERM to process 1234
kill -9 1234 # SIGKILL — a last resort
killall firefox # by name
pkill -f "python app" # by part of the command line
First try kill without -9: the program gets the chance to save its data and close its files. -9 only if it doesn't respond.
Background jobs in the shell:
sleep 100 & # & — start it in the background
echo $! # the PID of the last background process
jobs # the background jobs
fg # bring one back to the foreground
wait $! # wait for it to finish
The exit code of a process killed by a signal is 128 + the signal number: after SIGTERM it's 143, after SIGKILL — 137.
Task. Start sleep 60 in the background, save its PID, end the process with the SIGTERM signal, wait for it with wait and print the exit code.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.