Killing Processes
Sometimes processes misbehave. They freeze, eat CPU, or just won't quit. Time to learn process termination.
kill - Send Signals to Processes
Despite its name, kill actually sends signals. Termination is just one option.
Default signal is SIGTERM (15) - a polite "please stop."
Finding the PID
Or use pgrep:
SIGTERM vs SIGKILL
| Signal | Number | Effect |
|---|---|---|
| SIGTERM | 15 | Polite request to stop |
| SIGKILL | 9 | Forced termination |
SIGKILL is Dangerous
SIGKILL (kill -9) doesn't let the process clean up. Use it only if SIGTERM doesn't work. Try SIGTERM first, wait, then SIGKILL.
killall - Kill by Name
Easier than finding PIDs. But be careful - it kills ALL matching processes.
pkill - Pattern-based Kill
More flexible than killall.
The Kill Workflow
-
Try SIGTERM first (default)
hljs bashkill PID -
Wait a few seconds - check if process stopped
-
If still running, SIGKILL
hljs bashkill -9 PID
Why This Order?
SIGTERM lets the process:
- Save data
- Clean up temp files
- Close network connections
- Release resources properly
SIGKILL just yanks the plug.
Common Kill Scenarios
Frozen Application
Multiple Instances
All User's Processes
Keyboard Interrupts
In the terminal, these also send signals:
| Shortcut | Signal | Effect |
|---|---|---|
Ctrl+C | SIGINT | Interrupt (usually stops) |
Ctrl+Z | SIGTSTP | Suspend (stop but don't kill) |
Ctrl+\ | SIGQUIT | Quit with core dump |
A process isn't responding to `kill PID`. What should you try next?
Quick Reference
| Command | Effect |
|---|---|
kill PID | Send SIGTERM |
kill -9 PID | Send SIGKILL (force) |
killall name | Kill all by name |
pkill pattern | Kill by pattern |
pkill -9 pattern | Force kill by pattern |
Ctrl+C | Interrupt foreground |
Key Takeaways
killsends signals (SIGTERM by default)- Always try SIGTERM before SIGKILL
- SIGKILL (
-9) is forceful - use as last resort killallandpkillkill by name/pattern- Ctrl+C sends SIGINT to foreground process
Next: understanding more signals.