Overview
killall is a powerful tool that allows you to terminate multiple processes by their name instead of their Process ID (PID). Since it targets all instances with the same name, it's particularly convenient for closing all windows or background services of a specific application.
Key Features
- Termination based on process name
- Supports sending various signals (default SIGTERM)
- Can filter by user, time, and other criteria
- Handles multiple instances simultaneously
Key Options
The killall command offers various options to finely control the process termination method and targets.
Basic Operation and Signals
Process Filtering
Generated command:
Try combining the commands.
Description:
`killall` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Various usage examples of the killall command.
Terminate All Processes of a Specific Name
killall firefox
Terminates all instances of the Firefox web browser. It sends the default SIGTERM signal (a graceful termination request).
Force Termination with a Specific Signal
killall -s SIGKILL chrome
Terminates all instances of the Chrome web browser with the SIGKILL (forceful termination) signal. Use this signal with caution as it does not allow processes to perform cleanup operations.
Terminate in Interactive Mode
killall -i sshd
Prompts for confirmation before terminating each sshd (SSH daemon) process instance. Typing 'y' will proceed with termination.
Terminate Processes of a Specific User
killall -u user1
Terminates all processes running under the user 'user1'.
Wait for Process Termination
killall -w myapp
The command will wait until the currently running 'myapp' processes are completely terminated.
Installation
The killall command is typically installed by default as part of the 'psmisc' package on most Linux distributions. If it's not installed on your system, you can install it using the following commands.
Debian/Ubuntu
sudo apt update && sudo apt install psmisc
Install the psmisc package using the APT package manager.
CentOS/RHEL/Fedora
sudo yum install psmisc
# or
sudo dnf install psmisc
Install the psmisc package using the YUM or DNF package manager.
Tips & Precautions
Useful tips and precautions when using the killall command.
Caution when using SIGKILL (-9)
SIGKILL (signal number 9) forcefully terminates a process immediately, without giving it a chance to clean up open files or data. This can lead to data loss or system instability, so it should only be used as a last resort after attempting other signals (like SIGTERM).
- **Prefer SIGTERM (default)**: Most applications terminate gracefully when they receive SIGTERM.
- **Use SIGKILL as a last resort**: Only use it when a process is unresponsive.
Verify Exact Process Name
killall uses the exact process name. It's recommended to verify the exact name of the process you intend to terminate using a command like `ps aux | grep <process_name>`.
- Example: `ps aux | grep firefox`
Difference between killall and pkill
`killall` operates based on exact process names, whereas `pkill` can use regular expressions to match process names, allowing for more flexible searching and termination.
- `killall`: Exact name matching (e.g., `killall firefox`)
- `pkill`: Regular expression matching (e.g., `pkill -f 'firef[o]x'`)
- `pkill` extends the functionality of the `kill` command without directly specifying PIDs.
Caution when Terminating System Processes
Terminating essential system processes with `killall` can lead to system instability or crashes. Exercise extreme caution, especially when running with `root` privileges.
- Example: Never run commands like `killall systemd` or `killall init`.