kill Command Guide
The kill command sends signals to processes, most commonly to terminate them. Learn how to safely stop processes and use different signals.
5 min read•Last updated: 2024
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
kill PIDTerminate (SIGTERM)kill -9 PIDForce kill (SIGKILL)kill -lList signalsSignals
-15 (TERM)Graceful terminate-9 (KILL)Force kill-1 (HUP)Reload configBy Name
pkill nameKill by patternkillall nameKill by exact namepkill -u userKill user processesFind PID
pgrep nameGet PID by namepidof nameGet exact PIDps aux | grep nameSearch processesDownloadable Image Preview
Failed to generate preview
Basic Usage
The kill command sends a signal to a process. By default, it sends SIGTERM (signal 15), which asks the process to terminate gracefully.
bash
# Terminate process by PID
kill 1234
# Same as above (explicit SIGTERM)
kill -15 1234
kill -TERM 1234Common Signals
Frequently Used Signals
| SIGTERM (15) | Graceful termination (default) |
| SIGKILL (9) | Force kill (cannot be caught) |
| SIGHUP (1) | Hangup - often used to reload config |
| SIGINT (2) | Interrupt (like Ctrl+C) |
| SIGSTOP (19) | Pause process |
| SIGCONT (18) | Continue paused process |
bash
# List all available signals
kill -lGraceful vs Force Kill
Graceful termination (SIGTERM)
Allows the process to clean up, save data, and exit properly.
bash
kill 1234Force kill (SIGKILL)
Immediately terminates the process. Use only when SIGTERM doesn't work.
bash
kill -9 1234
# or
kill -KILL 1234Warning
Always try
kill (SIGTERM) first. Only use kill -9 when the process is unresponsive, as it doesn't allow cleanup.Kill by Name: pkill and killall
pkill - pattern-based killing
bash
# Kill by process name
pkill nginx
# Kill by exact name
pkill -x nginx
# Kill processes owned by user
pkill -u username
# Force kill by name
pkill -9 nginxkillall - kill by exact name
bash
# Kill all processes with exact name
killall nginx
# Force kill all
killall -9 nginx
# Interactive mode (confirm each)
killall -i nginxTip
pkill matches partial names by default, while killall requires exact matches. Use pgrep first to verify which processes will be affected.Finding Process IDs
bash
# Using pgrep
pgrep nginx
pgrep -a nginx # Show full command line
# Using ps and grep
ps aux | grep nginx
# Using pidof
pidof nginxPractical Examples
Kill multiple processes
bash
kill 1234 5678 9012Kill all user processes
bash
pkill -u usernameReload configuration (HUP signal)
bash
# Reload nginx config
kill -HUP $(pgrep nginx)
# Or using pkill
pkill -HUP nginxPause and resume a process
bash
# Pause
kill -STOP 1234
# Resume
kill -CONT 1234Kill unresponsive terminal process
bash
# From another terminal
ps aux | grep stuck_process
kill -9 <PID>Kill all background jobs
bash
# In current shell
kill $(jobs -p)Kill process tree
bash
# Kill process and all its children
pkill -P 1234 # Kill children
kill 1234 # Then kill parentSafe Termination Pattern
Follow this pattern for safe process termination:
bash
# 1. Try graceful shutdown
kill <PID>
# 2. Wait a few seconds
sleep 5
# 3. Check if process is still running
ps -p <PID>
# 4. If still running, force kill
kill -9 <PID>Signals Reference
All Common Signals
| 1 (SIGHUP) | Hangup - terminal closed or reload config |
| 2 (SIGINT) | Interrupt from keyboard (Ctrl+C) |
| 3 (SIGQUIT) | Quit from keyboard (Ctrl+\) |
| 9 (SIGKILL) | Kill immediately (cannot be caught) |
| 15 (SIGTERM) | Termination request (default) |
| 18 (SIGCONT) | Continue stopped process |
| 19 (SIGSTOP) | Stop process (cannot be caught) |
| 20 (SIGTSTP) | Stop from terminal (Ctrl+Z) |
Summary
kill is essential for process management. Key takeaways:
- Use
kill PIDfor graceful termination - Use
kill -9 PIDonly when necessary - Use
pkill nameto kill by process name - Use
pgrep nameto find PIDs first - Use
kill -HUPto reload configs