Mastering the killall Command: A Comprehensive Guide to Linux Process Termination
Introduction
When processes misbehave, hang, or consume excessive resources, every Linux user needs a reliable way to regain control. While tools like kill require you to know process IDs (PIDs) and pkill offers pattern-based termination, the killall command provides a straightforward, name-based approach to process management that has been a staple of Unix-like systems for decades.
The killall command does exactly what its name suggests—it kills all processes matching a given name. Unlike pkill which uses pattern matching, killall works with exact process names by default, making it more predictable and safer for routine process management. Originally developed for the Solaris operating system, killall has been part of the Linux psmisc package since the early days and remains an essential tool in every system administrator’s toolkit.
This comprehensive tutorial will guide you through everything you need to know about killall, from basic usage to advanced scenarios, with practical examples and safety best practices.
Understanding killall and Its Place in Process Management
Before diving into the command itself, let’s understand how killall fits into the broader landscape of Linux process termination tools:
flowchart TB
subgraph ProcessManagement["Linux Process Termination Tools"]
direction TB
subgraph ByPID["PID-Based"]
K1[kill] --> K2[kill -9 PID]
end
subgraph ByName["Name-Based"]
N1[killall] --> N2["Kills by exact name"]
P1[pkill] --> P2["Kills by pattern"]
end
subgraph Utility["Utility Commands"]
U1[pgrep] --> U2["Finds PIDs"]
U3[pidof] --> U4["Finds single PID"]
end
end
style ByPID fill:#ffcc99,stroke:#333
style ByName fill:#99ff99,stroke:#333
style Utility fill:#99ccff,stroke:#333
Key Characteristics of killall
| Feature | Description | Benefit |
|---|---|---|
| Exact Name Matching | Matches exact process names by default | Predictable, fewer surprises |
| Case Sensitivity | Case-sensitive matching | Precise targeting |
| Multiple Processes | Can target all instances of a process | Efficient bulk termination |
| Interactive Mode | Optional confirmation before killing | Enhanced safety |
| Process Age Filtering | Kill processes older/younger than specified time | Granular control |
| User-Specific | Target processes by owning user | Multi-user safety |
killall vs. Related Commands
| Command | Matching Type | Best For | Package |
|---|---|---|---|
| killall | Exact name | Safe, predictable termination | psmisc |
| pkill | Pattern/regex | Flexible matching | procps-ng |
| kill | PID | Precise single-process control | util-linux |
| xkill | Window click | GUI application termination | x11-utils |
Basic Syntax and Usage
Command Structure
killall [options] name [name ...]
Simplest Usage
# Kill all processes named "firefox"
killall firefox
# Kill multiple different processes
killall firefox chrome vlc
How killall Works
- Scans the process table - Examines all running processes
- Matches process names - Compares against the specified name(s)
- Sends SIGTERM (15) - Requests graceful termination by default
- Reports results - Shows how many processes were killed
# Example output
$ killall firefox
Terminated
# Or with multiple processes
$ killall firefox chrome
firefox: no process found
chrome(2 processes terminated)
Understanding Linux Signals
Before using killall effectively, you need to understand the signals it can send:
Common Signals Reference
| Signal | Number | Name | Description | Use Case |
|---|---|---|---|---|
| SIGTERM | 15 | Termination | Graceful shutdown request | Default, preferred method |
| SIGKILL | 9 | Kill | Force immediate termination | When SIGTERM fails |
| SIGHUP | 1 | Hang up | Reload configuration | Daemon configuration reload |
| SIGINT | 2 | Interrupt | Same as Ctrl+C | Interactive programs |
| SIGSTOP | 19 | Stop | Pause execution | Temporary suspension |
| SIGCONT | 18 | Continue | Resume stopped process | Resume execution |
| SIGUSR1 | 10 | User-defined | Application-specific | Custom actions |
| SIGUSR2 | 12 | User-defined | Application-specific | Custom actions |
Signal Behavior Diagram
flowchart LR
A[Running Process] -->|SIGTERM| B{Graceful<br/>Shutdown?}
B -->|Yes| C[Process Exits]
B -->|No/Blocked| D[Still Running]
D -->|SIGKILL| E[Force Terminated]
D -->|SIGSTOP| F[Suspended]
F -->|SIGCONT| A
style A fill:#99ff99,stroke:#333
style C fill:#99ff99,stroke:#333
style E fill:#ff9999,stroke:#333
style F fill:#ffcc99,stroke:#333
Command-Line Options Reference
Signal Options
| Option | Description | Example |
|---|---|---|
-signal | Send specific signal by number | killall -9 firefox |
-s signal | Send signal by name or number | killall -s SIGTERM firefox |
-SIGNAME | Send signal by name | killall -HUP nginx |
Matching Options
| Option | Description | Example |
|---|---|---|
-e | Exact match (no truncation) | killall -e firefox |
-I | Case-insensitive matching | killall -I Firefox |
-r | Use regular expressions | killall -r "^firefox" |
-u user | Kill only processes owned by user | killall -u joshua firefox |
Safety and Confirmation Options
| Option | Description | Example |
|---|---|---|
-i | Interactive mode (ask before killing) | killall -i firefox |
-w | Wait for processes to die | killall -w firefox |
-v | Verbose output | killall -v firefox |
Process Age Options
| Option | Description | Example |
|---|---|---|
-o time | Kill processes OLDER than time | killall -o 1h firefox |
-y time | Kill processes YOUNGER than time | killall -y 5m firefox |
Additional Options
| Option | Description | Example |
|---|---|---|
-q | Quiet mode (no output) | killall -q firefox |
-V | Display version information | killall -V |
--help | Display help information | killall --help |
Practical Examples
1. Basic Process Termination
# Kill all firefox processes gracefully (SIGTERM)
killall firefox
# Force kill all firefox processes (SIGKILL)
killall -9 firefox
# Or using signal name
killall -SIGKILL firefox
2. Configuration Reload
Many daemons respond to SIGHUP by reloading their configuration without stopping:
# Reload nginx configuration
killall -HUP nginx
# Or using signal number
killall -1 nginx
# Reload SSH daemon
killall -HUP sshd
# Reload Apache
killall -HUP apache2
3. Interactive Mode for Safety
When you’re unsure about what will be killed:
# Ask for confirmation before killing each process
killall -i firefox
# Sample interaction:
# Kill firefox(1234) ? (y/n) y
# Kill firefox(1235) ? (y/n) n
4. User-Specific Termination
On multi-user systems, limit the scope to specific users:
# Kill all firefox processes owned by user "joshua"
killall -u joshua firefox
# Kill all processes owned by a specific user (dangerous!)
# killall -u olduser
# Combine with other options
killall -u www-data -HUP nginx
5. Process Age-Based Termination
Kill processes based on how long they’ve been running:
# Kill firefox processes older than 1 hour
killall -o 1h firefox
# Kill processes younger than 5 minutes
killall -y 5m firefox
# Time suffixes: s (seconds), m (minutes), h (hours), d (days)
killall -o 30m chrome # Older than 30 minutes
killall -y 10s python # Younger than 10 seconds
6. Case-Insensitive Matching
When you’re not sure about the exact capitalization:
# Match Firefox, firefox, FIREFOX, etc.
killall -I firefox
# Useful for cross-platform scripts
killall -I chrome
7. Regular Expression Matching
For more complex matching scenarios:
# Kill all processes starting with "firefox"
killall -r "^firefox"
# Kill processes matching a pattern
killall -r ".*chrome.*"
# Be careful with broad patterns!
8. Verbose and Quiet Modes
Control the output level:
# Verbose - show what's happening
killall -v firefox
# Output: Killed firefox(1234) with signal 15
# Quiet - no output at all
killall -q firefox
# No output, check exit code ($?) for success
9. Waiting for Processes to Terminate
Ensure processes are fully terminated before continuing:
# Kill firefox and wait for it to die
killall -w firefox
# Useful in scripts
killall -w myservice
echo "Service has fully terminated"
10. Multiple Process Types
Kill several different processes at once:
# Kill all browsers
killall firefox chrome chromium safari
# Kill media applications
killall vlc spotify rhythmbox
# Kill development servers
killall node python ruby
Advanced Usage Scenarios
System Administration Scripts
Graceful Service Shutdown
#!/bin/bash
# graceful-shutdown.sh - Safely stop services
SERVICES="nginx postgresql redis"
for service in $SERVICES; do
echo "Stopping $service..."
# Try graceful shutdown first
if killall -q $service; then
echo "Sent SIGTERM to $service"
# Wait up to 10 seconds for graceful shutdown
for i in {1..10}; do
if ! pgrep -x $service > /dev/null; then
echo "$service stopped gracefully"
break
fi
sleep 1
done
# Force kill if still running
if pgrep -x $service > /dev/null; then
echo "$service didn't stop, forcing..."
killall -9 $service
fi
else
echo "$service was not running"
fi
done
Memory Emergency Cleanup
#!/bin/bash
# emergency-cleanup.sh - Free memory by stopping heavy apps
echo "Memory usage is critical. Stopping non-essential processes..."
# Stop browsers (memory hogs)
killall -q firefox chrome chromium
# Stop media players
killall -q vlc spotify
# Stop development tools
killall -q code atom sublime_text
# Wait for termination
sleep 2
echo "Cleanup complete. Checking memory..."
free -h
Development Workflow Automation
Clean Development Environment
#!/bin/bash
# dev-cleanup.sh - Clean up development processes
echo "Cleaning up development environment..."
# Kill local servers
killall -q "rails server" "npm start" "python manage.py"
killall -q -f "node.*server" "python.*app.py"
# Kill test runners
killall -q jest pytest mocha
# Kill build processes
killall -q webpack gulp grunt
# Kill database connections (be careful!)
# killall -q -u $(whoami) postgres mysql
echo "Development environment cleaned!"
Test Suite Coordination
#!/bin/bash
# run-tests.sh - Run tests with proper cleanup
# Kill any leftover test processes from previous runs
killall -q -y 1h firefox # Only if younger than 1 hour
# Start test server
python test_server.py &
SERVER_PID=$!
# Run tests
pytest tests/
TEST_RESULT=$?
# Cleanup
killall -q python test_server.py
exit $TEST_RESULT
Docker and Container Management
#!/bin/bash
# container-cleanup.sh - Clean up container processes
# Kill all container processes for a specific image
killall -q -r "docker.*myapp"
# Kill container runtime processes
killall -q containerd-shim
# Wait for cleanup
sleep 2
# Verify cleanup
if pgrep -f "docker.*myapp" > /dev/null; then
echo "Warning: Some processes still running"
pgrep -a -f "docker.*myapp"
fi
Best Practices and Safety Guidelines
1. Always Verify Before Killing
# Bad: Immediate kill without checking
killall -9 firefox
# Good: Check what's running first
pgrep -a firefox
# Then proceed with graceful kill
killall firefox
sleep 2
# Verify it's gone, force if needed
pgrep firefox && killall -9 firefox
2. Use Interactive Mode When Uncertain
# When you're not 100% sure
killall -i python
# Review each match before confirming
3. Prefer Graceful Over Forceful
# Step 1: Try graceful shutdown
killall nginx
# Step 2: Wait briefly
sleep 3
# Step 3: Check if still running
if pgrep nginx > /dev/null; then
echo "Nginx didn't stop, forcing..."
killall -9 nginx
fi
4. Be Specific on Multi-User Systems
# Bad: Affects all users
killall chrome
# Good: Limit to your own processes
killall -u $(whoami) chrome
# Or check if process is yours
ps -o pid,user,comm -p $(pgrep chrome)
5. Handle Case Sensitivity
# Be aware of case sensitivity
killall Firefox # Won't match "firefox"
killall FIREFOX # Won't match "Firefox"
# Use -I for case-insensitive when needed
killall -I firefox # Matches any case
6. Script Safety Checks
#!/bin/bash
# Safe killall wrapper
PROCESS_NAME=$1
# Check if process exists
if ! pgrep -x "$PROCESS_NAME" > /dev/null; then
echo "Process '$PROCESS_NAME' not found"
exit 0
fi
# Show what will be killed
echo "The following processes will be terminated:"
pkill -a -x "$PROCESS_NAME"
# Ask for confirmation
read -p "Continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
killall "$PROCESS_NAME"
echo "Process terminated"
else
echo "Cancelled"
fi
7. Signal Selection Guide
| Scenario | Recommended Signal | Command |
|---|---|---|
| Graceful application shutdown | SIGTERM (15) | killall firefox |
| Force immediate termination | SIGKILL (9) | killall -9 firefox |
| Daemon configuration reload | SIGHUP (1) | killall -HUP nginx |
| Interactive program interrupt | SIGINT (2) | killall -INT app |
| Pause process execution | SIGSTOP (19) | killall -STOP app |
| Resume stopped process | SIGCONT (18) | killall -CONT app |
Troubleshooting Common Issues
Issue: “no process found”
# Problem: Process name doesn't match
$ killall FireFox
FireFox: no process found
# Solutions:
# 1. Check actual process name
ps aux | grep -i firefox
# 2. Use case-insensitive matching
killall -I firefox
# 3. Use pgrep to verify
pgrep -l firefox
Issue: Permission Denied
# Problem: Can't kill other users' processes
$ killall nginx
nginx(1234): Operation not permitted
# Solutions:
# 1. Use sudo for system processes
sudo killall nginx
# 2. Limit to your own processes
killall -u $(whoami) nginx
# 3. Check process ownership
ps -o pid,user,comm -p $(pgrep nginx)
Issue: Wrong Processes Killed
# Problem: Similar process names
$ killall python
# Kills ALL Python processes, including system ones!
# Solutions:
# 1. Be more specific
killall -f "python myapp.py"
# 2. Use user filtering
killall -u $(whoami) python
# 3. Check first with pgrep
pgrep -a python
Issue: Zombie Processes
# Problem: Can't kill zombie processes directly
# Zombies are already dead, waiting for parent
# Solution: Kill the parent process
# Find parent PID
ps aux | grep -w Z
# Kill parent (be careful!)
killall -9 parent_process_name
Issue: Kernel Processes
# Problem: Can't kill kernel threads
$ killall kworker
kworker(1234): Operation not permitted
# Solution: Kernel processes cannot be killed
# These are essential system threads
# If causing issues, check hardware/drivers
Comparison with Alternative Commands
killall vs. pkill
| Feature | killall | pkill |
|---|---|---|
| Default matching | Exact name | Pattern/regex |
| Case sensitivity | Case-sensitive | Case-sensitive |
| Pattern support | With -r flag | Native support |
| Interactive mode | Yes (-i) | No |
| Process age filtering | Yes (-o, -y) | No |
| Package | psmisc | procps-ng |
| Output | Shows count killed | Silent by default |
When to Use Each Command
flowchart TD
A[Need to terminate processes] --> B{Know the exact name?}
B -->|Yes| C[Use killall]
B -->|No/Pattern| D[Use pkill]
B -->|Have PID| E[Use kill]
C --> C1[Safe and predictable]
C --> C2[Good for scripts]
D --> D1[Flexible matching]
D --> D2[Regex support]
E --> E1[Precise control]
E --> E2[Single process]
style A fill:#f9f,stroke:#333
style B fill:#bbf,stroke:#333
Command Equivalents
| Task | killall | pkill | kill + pgrep |
|---|---|---|---|
| Kill by name | killall firefox | pkill firefox | kill $(pgrep firefox) |
| Force kill | killall -9 firefox | pkill -9 firefox | kill -9 $(pgrep firefox) |
| Reload config | killall -HUP nginx | pkill -HUP nginx | kill -HUP $(pgrep nginx) |
| User-specific | killall -u user firefox | pkill -u user firefox | Complex pipeline |
| Interactive | killall -i firefox | Not available | Not available |
Real-World Use Cases
System Administration
Log Rotation
#!/bin/bash
# Rotate application logs
# Compress old logs
gzip /var/log/myapp/*.log
# Signal application to reopen log files
killall -HUP myapp
echo "Log rotation complete"
Service Management
#!/bin/bash
# restart-service.sh
SERVICE=$1
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name>"
exit 1
fi
echo "Restarting $SERVICE..."
# Stop service
if killall -q $SERVICE; then
echo "Stopping $SERVICE..."
sleep 2
# Force if needed
if pgrep -x $SERVICE > /dev/null; then
killall -9 $SERVICE
fi
fi
# Start service
/usr/local/bin/$SERVICE &
echo "$SERVICE restarted"
Development and Testing
Cleanup Script
#!/bin/bash
# Post-test cleanup
echo "Cleaning up test environment..."
# Kill test browsers
killall -q -y 5m firefox chrome # Only recent ones
# Kill test servers
killall -q node python ruby
# Kill test databases
killall -q redis-server mongod
echo "Cleanup complete"
Parallel Build Control
#!/bin/bash
# Control parallel build processes
# Limit concurrent gcc processes to prevent overload
while [ $(pgrep -c gcc) -gt 4 ]; do
echo "Too many gcc processes, waiting..."
sleep 1
done
# If build hangs, clean up
if [ "$1" = "cleanup" ]; then
killall -9 gcc g++ make
fi
Home Automation and IoT
#!/bin/bash
# Monitor and control home automation services
# Restart stuck home assistant
if ! curl -s http://localhost:8123/api/health > /dev/null; then
echo "Home Assistant unresponsive, restarting..."
killall -9 python3 hass
sleep 5
hass &
fi
# Reload configuration
if [ "$1" = "reload" ]; then
killall -HUP hass
fi
Frequently Asked Questions
What’s the difference between killall and killall5?
Important distinction: killall kills processes by name, while killall5 (also known as killall on some SysV systems) kills all processes except kernel threads and the calling process. killall5 is extremely dangerous and typically used only during system shutdown. On Linux, these are separate commands from different packages.
Why does killall say “no process found” when I can see the process?
Common causes:
- Case sensitivity: The process name has different capitalization
- Truncated names: Process names in
psmay be truncated; usecat /proc/PID/commfor the real name - Different name: The binary name differs from the display name
- Kernel process: Some processes are kernel threads and can’t be killed
Can I use killall on macOS?
macOS has a killall command, but it behaves differently—it kills by application name rather than process name. For example, killall Safari kills the Safari browser. This is different from Linux killall which uses the process name from /proc/PID/comm.
How do I kill a process that keeps respawning?
If a process restarts automatically (likely managed by systemd or another supervisor):
# Stop the service properly
sudo systemctl stop servicename
# Or disable auto-restart
sudo systemctl disable servicename
# Then kill
sudo killall servicename
Is killall safe to use in production?
Yes, when used carefully:
- Always test commands in a development environment first
- Use
-i(interactive) when uncertain - Verify with
pgrepbefore killing - Use user-specific targeting (
-u) on shared systems - Have rollback procedures for critical services
Can killall kill system processes?
killall can target any process you have permission to signal. Regular users can only kill their own processes. Root can kill any user process, but kernel threads cannot be killed by any user.
What’s the safest way to terminate a process?
# 1. Check what's running
pgrep -a process_name
# 2. Try graceful termination
killall process_name
# 3. Wait a few seconds
sleep 3
# 4. Check if still running
pgrep process_name
# 5. Force kill only if necessary
killall -9 process_name
How do I list all signals killall supports?
# List signal names and numbers
killall -l
# Or
kill -l
Why use killall instead of pkill?
Use killall when:
- You know the exact process name
- You want predictable, exact matching
- You need interactive confirmation
- You want process age filtering
- You prefer safer default behavior
Use pkill when:
- You need pattern matching
- You want to match against full command lines
- You need more flexible selection criteria
Conclusion
The killall command is an essential tool for Linux process management, offering a straightforward and predictable way to terminate processes by name. Its exact-name matching by default makes it safer than pattern-based alternatives for routine process management tasks.
Key Takeaways
- Default safety:
killallmatches exact names, reducing accidental terminations - Graceful first: Always try SIGTERM before resorting to SIGKILL
- Verify before killing: Use
pgrepor-iflag to confirm targets - User awareness: Use
-uon multi-user systems to limit scope - Signal knowledge: Understand SIGTERM vs SIGKILL and when to use each
- Script integration:
killallis excellent for automation when used carefully
When to Choose killall
- ✅ You know the exact process name
- ✅ Safety and predictability are priorities
- ✅ You need interactive confirmation
- ✅ You’re working with time-based process filtering
- ❌ You need pattern or regex matching (use
pkill) - ❌ You’re on macOS (behavior differs significantly)
Mastering killall will make you more efficient at managing Linux processes while maintaining system stability and avoiding accidental disruptions.
Quick Reference Card
Basic Commands
killall firefox # Graceful kill
killall -9 firefox # Force kill
killall -HUP nginx # Reload config
killall -i firefox # Interactive mode
User and Permission
killall -u username firefox # Kill user's processes
sudo killall nginx # Kill system processes
Matching Options
killall -I Firefox # Case-insensitive
killall -e firefox # Exact match (no truncation)
killall -r "^firefox" # Regex pattern
Process Age
killall -o 1h firefox # Older than 1 hour
killall -y 5m firefox # Younger than 5 minutes
Output Control
killall -v firefox # Verbose
killall -q firefox # Quiet
killall -w firefox # Wait for termination
Multiple Processes
killall firefox chrome vlc # Kill multiple
killall -l # List all signals
Ready to take control of your Linux processes? Master killall and manage your system with confidence!
This tutorial covers the Linux implementation of killall from the psmisc package. Some options may vary on other Unix-like systems. Always test commands in a safe environment before using in production.