kill: Stopping Processes
Signals.
Sometimes a program freezes, or runs forever, and control C can't reach it, because it's not in your terminal. Then you need to stop it by its PID. That's what kill does.

- A program won't stop
- Ctrl+C can't reach it
- kill it by its PID
Find it, then kill it
First, find the PID. P grep backup prints the PID of anything called backup. Then kill, and that number, asks it to stop. P grep again finds nothing. The backup script is gone.
pgrep backup 21 kill $(pgrep backup) pgrep backup || echo "not running" not running
Signals
Kill doesn't really kill. It sends a signal, a small message. The default is term, which politely asks the program to finish, and clean up. Kill dash nine sends kill, which stops it instantly, with no chance to clean up. Use it only when the polite way fails. Control C sends a signal too, called int.
| Signal | Number | Meaning |
|---|---|---|
| TERM | 15 | please stop (default) |
| KILL | 9 | stop now, no clean up |
| INT | 2 | what Ctrl + C sends |
| HUP | 1 | reload, or the terminal closed |
Kill by name
Typing PIDs gets tiring. P kill stops processes by name, and kill all does something similar. Be careful, though. A short name might match more than you expect. P grep dash L first shows what would be matched, with names.
| key | value |
|---|---|
| kill PID | polite stop |
| kill -9 PID | forced stop |
| pkill name | stop by name |
| pgrep -l name | check first |
Summary
Kill sends a signal to a process. The default asks it to stop, and dash nine forces it. P grep finds PIDs, and P kill stops by name. Next, services, the programs that run all the time.
Key takeaways- pgrep name
- kill PID
- kill -9 PID