Skip to content
Go back

Mastering the killall Command: A Comprehensive Guide to Linux Process Termination

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

FeatureDescriptionBenefit
Exact Name MatchingMatches exact process names by defaultPredictable, fewer surprises
Case SensitivityCase-sensitive matchingPrecise targeting
Multiple ProcessesCan target all instances of a processEfficient bulk termination
Interactive ModeOptional confirmation before killingEnhanced safety
Process Age FilteringKill processes older/younger than specified timeGranular control
User-SpecificTarget processes by owning userMulti-user safety
CommandMatching TypeBest ForPackage
killallExact nameSafe, predictable terminationpsmisc
pkillPattern/regexFlexible matchingprocps-ng
killPIDPrecise single-process controlutil-linux
xkillWindow clickGUI application terminationx11-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

  1. Scans the process table - Examines all running processes
  2. Matches process names - Compares against the specified name(s)
  3. Sends SIGTERM (15) - Requests graceful termination by default
  4. 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

SignalNumberNameDescriptionUse Case
SIGTERM15TerminationGraceful shutdown requestDefault, preferred method
SIGKILL9KillForce immediate terminationWhen SIGTERM fails
SIGHUP1Hang upReload configurationDaemon configuration reload
SIGINT2InterruptSame as Ctrl+CInteractive programs
SIGSTOP19StopPause executionTemporary suspension
SIGCONT18ContinueResume stopped processResume execution
SIGUSR110User-definedApplication-specificCustom actions
SIGUSR212User-definedApplication-specificCustom 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

OptionDescriptionExample
-signalSend specific signal by numberkillall -9 firefox
-s signalSend signal by name or numberkillall -s SIGTERM firefox
-SIGNAMESend signal by namekillall -HUP nginx

Matching Options

OptionDescriptionExample
-eExact match (no truncation)killall -e firefox
-ICase-insensitive matchingkillall -I Firefox
-rUse regular expressionskillall -r "^firefox"
-u userKill only processes owned by userkillall -u joshua firefox

Safety and Confirmation Options

OptionDescriptionExample
-iInteractive mode (ask before killing)killall -i firefox
-wWait for processes to diekillall -w firefox
-vVerbose outputkillall -v firefox

Process Age Options

OptionDescriptionExample
-o timeKill processes OLDER than timekillall -o 1h firefox
-y timeKill processes YOUNGER than timekillall -y 5m firefox

Additional Options

OptionDescriptionExample
-qQuiet mode (no output)killall -q firefox
-VDisplay version informationkillall -V
--helpDisplay help informationkillall --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

ScenarioRecommended SignalCommand
Graceful application shutdownSIGTERM (15)killall firefox
Force immediate terminationSIGKILL (9)killall -9 firefox
Daemon configuration reloadSIGHUP (1)killall -HUP nginx
Interactive program interruptSIGINT (2)killall -INT app
Pause process executionSIGSTOP (19)killall -STOP app
Resume stopped processSIGCONT (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

Featurekillallpkill
Default matchingExact namePattern/regex
Case sensitivityCase-sensitiveCase-sensitive
Pattern supportWith -r flagNative support
Interactive modeYes (-i)No
Process age filteringYes (-o, -y)No
Packagepsmiscprocps-ng
OutputShows count killedSilent 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

Taskkillallpkillkill + pgrep
Kill by namekillall firefoxpkill firefoxkill $(pgrep firefox)
Force killkillall -9 firefoxpkill -9 firefoxkill -9 $(pgrep firefox)
Reload configkillall -HUP nginxpkill -HUP nginxkill -HUP $(pgrep nginx)
User-specifickillall -u user firefoxpkill -u user firefoxComplex pipeline
Interactivekillall -i firefoxNot availableNot 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:

  1. Case sensitivity: The process name has different capitalization
  2. Truncated names: Process names in ps may be truncated; use cat /proc/PID/comm for the real name
  3. Different name: The binary name differs from the display name
  4. 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:

  1. Always test commands in a development environment first
  2. Use -i (interactive) when uncertain
  3. Verify with pgrep before killing
  4. Use user-specific targeting (-u) on shared systems
  5. 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:

Use pkill when:


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

  1. Default safety: killall matches exact names, reducing accidental terminations
  2. Graceful first: Always try SIGTERM before resorting to SIGKILL
  3. Verify before killing: Use pgrep or -i flag to confirm targets
  4. User awareness: Use -u on multi-user systems to limit scope
  5. Signal knowledge: Understand SIGTERM vs SIGKILL and when to use each
  6. Script integration: killall is excellent for automation when used carefully

When to Choose killall

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.


Share this post on:

Previous Post
Local SEO Strategies: How to Dominate Google Maps and Local Search in 2025
Next Post
Mastering Linux Process Management: A Complete Guide to pgrep, pkill, and pidwait