Introduction
In the Linux environment, managing running processes is a daily task for system administrators, developers, and power users. Sometimes it is necessary to stop a program that has hung, consumes too many resources, or is simply no longer needed. While the kill command allows terminating processes by specifying their identifier (PID), there is a more direct alternative when you know the process name: killall. This article explains in detail how killall works, its syntax, the most useful options, and some practical examples for using it safely and efficiently.
What is killall?
killall is a utility that belongs to the psmisc package in most Linux distributions. Its main function is to send a signal to all processes whose name exactly matches the provided argument. Unlike kill, which acts on a specific PID, killall acts on all processes that share the same name, which can be very handy when you have multiple instances of the same program running.
Basic syntax
The simplest way to use killall is:
killall process_name
This command will send the SIGTERM signal (number 15) to all processes whose name is exactly process_name. If the process does not respond to SIGTERM, you can escalate to a stronger signal such as SIGKILL (number 9) using the -s or --signal option.
Useful options
-s SIGNALor--signal=SIGNAL: specifies the signal to send. For example,-s SIGKILLor-9.-ior--interactive: asks for confirmation before killing each process.-vor--verbose: shows information about the processes being terminated.-eor--exact: requires an exact match of the name (by default killall ignores case differences and allows partial matches up to a certain length).-gor--process-group: kills the entire process group instead of just the individual processes.-ror--regexp: interprets the name as a regular expression.-u useror--user=user: limits the action to processes belonging to a specific user.
Practical examples
Imagine you have several hung Firefox browser windows and you want to close them all:
killall firefox
If you want to see which processes will be affected before acting, combine the -v option:
killall -v firefox
To force immediate termination, send SIGKILL:
killall -s SIGKILL firefox
or its short form:
killall -9 firefox
If you only want to kill the Firefox processes belonging to user juan:
killall -u juan firefox
In case you need to match a pattern, for example to terminate all processes that start with chrome (such as chrome, chrome-sandbox), you can use the regular expression option:
killall -r '^chrome.*'
Finally, if you prefer the system to ask you before killing each process, use interactive mode:
killall -i firefox
Precautions and best practices
Although killall is very convenient, indiscriminate use can cause unwanted effects. Keep the following points in mind:
- Verify the exact process name. A typo could terminate critical system processes.
- Use the
-eoption to require an exact match when there is risk of confusion with similar names. - Prefer to first send
SIGTERMand wait a few seconds before resorting toSIGKILL. This allows processes to release resources and save their state. - On production systems, consider using
pkillwith more specific filters or checking the process list withpsbefore running killall. - If you are in a multi-user environment, limit the action with the
-uoption to avoid affecting other users.
Conclusion
The killall command is a powerful and simple tool for terminating processes in Linux by name. Knowing its syntax, options, and best practices, you can efficiently manage the processes on your system without needing to look up individual PIDs. Always remember to act with caution, verify the targets, and use gentle signals before resorting to brute force. With this knowledge, you will be better prepared to keep your Linux environment stable and responsive.
This post is also available in ESPAÑOL.