To stop a process, the kernel sends it a signal. A signal is a short message from the kernel to a process. Each signal has a name and a number.
| Signal | Number | Means | The process can ignore it |
|---|---|---|---|
TERM | 15 | Please stop. Clean up first | Yes |
INT | 2 | Stop (sent by Ctrl+C) | Yes |
KILL | 9 | Stop now | No |
kill: send a signal
kill sends a signal to a process. Give it the PID. With no flag, it sends TERM:
text
learner@tidepool:~$ ps -e | grep report
2045 ? 00:00:00 report
learner@tidepool:~$ kill 2045
learner@tidepool:~$ ps -e | grep report
learner@tidepool:~$kill writes nothing when it works. Check with ps.
kill 2045
Kernelsends the signal
TERM
process 2045cleans up, then ends
kill -9: when TERM does not work
Some processes ignore TERM, or they are stuck. Then send KILL:
text
learner@tidepool:~$ kill -9 2050The process cannot ignore KILL. It stops at once and cannot clean up, so try TERM first.
You can stop only your own processes
| Error | Means |
|---|---|
bash: kill: (530) - Operation not permitted | The process belongs to another account |
bash: kill: (9999) - No such process | No process has that PID |
The root account can send a signal to any process.
Ctrl+C
A program that runs in your terminal keeps the prompt until it ends. Push Ctrl+C to send it the INT signal. This is how you stop a command that takes too long.