GICT knowledge base
How to Use the killall Command to Terminate Processes in Linux
Published
When you run multiple applications or scripts on a Linux system, you may occasionally need to stop or restart a process that is stuck, misbehaving, or no longer needed. While there are several ways to terminate processes, the killall command offers a simple and efficient method for ending processes by name, rather than by process ID (PID). This can save you time and help you manage your system more effectively.
This article explains what the killall command does, how to install and use it, its advantages and potential drawbacks, and provides step-by-step examples of real-world scenarios. By the end, you will be able to confidently use killall to manage processes on your Linux machine.
Prerequisites
- Access to a Linux machine or terminal
- Sudo or root privileges for terminating processes started by other users (if needed)
- Basic familiarity with the Linux command line
Introduction to the killall Command
The killall command is a process management tool that allows you to terminate processes by their program name rather than by PID. This makes it especially useful when you need to stop all instances of a specific program, such as a web server, editor, or script, without searching for their PIDs one by one.
Unlike the kill command, which requires you to specify the PID of each process, killall can act on all processes with a given name in a single command. This is particularly helpful when dealing with multiple processes of the same type or managing resources on multi-user systems.
How killall Works
The basic syntax for killall is:
$ killall [options] process_name
process_name is the name of the executable or command you want to terminate.
options allow you to modify the behavior of killall, such as sending different signals or matching only processes belonging to a specific user.
By default, killall sends the SIGTERM signal, which requests the process to terminate gracefully. You can specify other signals (such as SIGKILL or SIGHUP) to force immediate termination or trigger specific behaviors.
Installing killall
Most modern Linux distributions include killall as part of the psmisc package. To check if killall is installed, run:
$ killall --version
If you see version information, you are ready to proceed. If not, you can install it using your package manager.
On Ubuntu/Debian
$ sudo apt update
$ sudo apt install psmisc
On CentOS/RHEL
$ sudo yum install psmisc
On Fedora
$ sudo dnf install psmisc
After installation, verify that killall is available:
$ killall --version
Viewing Running Processes
Before terminating processes, it’s a good idea to see what is currently running on your system. You can use the ps, top, or pgrep commands.
To display all running processes:
$ ps aux
To show all processes with a specific name, such as firefox:
$ pgrep -l firefox
Terminating Processes with killall
The most basic usage of killall is to terminate all processes with a given name. For example, to stop all instances of the firefox browser:
$ killall firefox
This command sends the SIGTERM signal to each firefox process, asking them to close cleanly.
Example: Stopping a Text Editor
Suppose you have multiple gedit windows open and want to close them all at once:
$ killall gedit
All running instances of the gedit text editor will receive the SIGTERM signal and should close.
Example: Terminating a Shell Script
If you are running a script called backup.sh that is hanging or taking too long, you can terminate all instances:
$ killall backup.sh
NOTE: The process name must match the name of the executable or script as it appears in the process list (ps aux). If unsure, check with pgrep -l or ps.
Using Signals with killall
By default, killall uses SIGTERM (signal 15), which allows the process to clean up and exit gracefully. Sometimes, a process may ignore SIGTERM or not terminate quickly enough. In these cases, you can send a different signal.
Sending SIGKILL
SIGKILL (signal 9) forces the process to terminate immediately, without cleanup:
$ killall -9 process_name
Example:
$ killall -9 firefox
This forcibly ends all firefox processes, even if they are unresponsive.
Sending SIGHUP
SIGHUP (signal 1) is often used to ask a process to reload configuration or restart. Some daemons respond to SIGHUP instead of SIGTERM:
$ killall -1 nginx
Check the documentation for your specific application to see how it responds to signals.
Listing Available Signals
To see all available signals on your system:
$ killall -l
This displays a list of supported signals and their numbers.
Targeting Processes by User
You can use the -u option to limit killall to processes owned by a specific user.
For example, to terminate all python3 processes started by the user alice:
$ killall -u alice python3
Case Sensitivity and Exact Matches
On Linux, process names are case-sensitive. killall python is different from killall Python. Always use the exact name as it appears in the process list.
By default, killall matches the full name of the process. On some systems, you can use the -I option for a case-insensitive match:
$ killall -I process_name
Dry Run: Preview What Will Be Killed
Before actually terminating processes, you can use the -i (interactive) or -v (verbose) options.
The -i option prompts you before killing each process:
$ killall -i firefox
The -v option prints information about what is being killed:
$ killall -v firefox
Scheduling Delayed or Timed Kills
You can use killall with the -w option to wait for all processes to be terminated before returning. This can be useful in scripts:
$ killall -w firefox
echo "All Firefox processes have exited."
Or, schedule a delayed kill using sleep:
$ sleep 10 && killall firefox
Combining killall with Other Tools
Example: Kill All Processes Matching a Pattern
Use pgrep to find processes by pattern, and kill them with kill if needed:
$ pgrep -f 'pattern' | xargs kill
Example: Kill Backgrounded Jobs in a Shell Session
If you have background jobs started with &, you can list them with:
$ jobs
Then, use killall by name or kill by PID as needed.
Script Automation with killall
You can use killall in scripts to automate cleanup, restart services, or manage complex workflows. For example, create a script to restart an application:
#!/bin/bash
killall myapp
sleep 2
myapp &
echo "myapp restarted."
Troubleshooting killall
Error: No Process Killed
If killall reports “no process found” or “no process killed,” check the exact name and spelling of the process.
Permission Denied
You may need sudo privileges:
$ sudo killall nginx
Not Available on All UNIX Systems
On some UNIX variants (such as macOS), the behavior of killall is different. Always check the manual.
Processes Restart Automatically
Some system services may restart automatically. Use systemctl or service to safely manage them.
Protecting Critical Processes
Be careful when using killall with root privileges. Terminating critical system processes can cause instability.
WARNING
Always double-check the process name and which users own the processes before issuing killall commands.
Best Practices for Using killall
- Always verify the process name with ps or pgrep.
- Use interactive mode if working on a production system.
- Use user targeting to avoid killing other users’ processes.
- Test scripts on non-critical systems first.
- Use systemctl for persistent system services.
Alternative Process Management Tools
- kill: Terminate processes by PID.
- pkill: Pattern-based process termination.
- xkill: Graphically kill a window.
- systemctl / service: Manage system services.
Conclusion
The killall command is a valuable process management tool for Linux users and administrators. By allowing you to terminate processes by name, it simplifies common tasks such as stopping applications, handling runaway scripts, or cleaning up system resources. With support for different signals, user targeting, and integration with scripts, killall helps you keep your Linux environment stable and under control.
Always use killall responsibly, especially when running as root, to avoid unintended system disruptions. With practice and care, killall becomes an indispensable part of your Linux toolbox for effective process management.
Related guides
How to Set Up zram on a Small VPS
Configure zram on Ubuntu with kernel and swap checks. Understand compressed memory limits, monitor real use and avoid unsafe swap-file changes.
LinuxHow to Find Services That Need a Restart After Updates with needrestart
Find services using outdated libraries with needrestart on Ubuntu. Read restart reports, review automatic restart policy and plan maintenance safely.
LinuxHow to Limit a Linux Service’s Memory with systemd
Limit a Linux service with systemd MemoryHigh, MemoryMax and swap controls. Check cgroup support, diagnose pressure and remove only your own policy.
LinuxHow to Protect SSH with CrowdSec on Ubuntu
Protect SSH with CrowdSec on Ubuntu. Connect log detection to firewall enforcement and test temporary blocking without losing administrator access.
