How to pkill linux
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- pkill sends signals to processes, most commonly SIGTERM (terminate) or SIGKILL (force kill).
- It allows killing processes by name, user, terminal, or matching command-line arguments.
- The `-f` option enables matching against the full command line.
- Signals can be specified using numbers (e.g., -9 for SIGKILL) or names (e.g., -KILL).
- It's often used for terminating unresponsive applications or background services.
What is the pkill command in Linux?
The pkill command in Linux is a versatile utility that allows you to send signals to processes based on a specified pattern. Unlike the kill command, which requires the process ID (PID) of the process you want to affect, pkill can identify and signal processes using their names, the user who owns them, the terminal they are associated with, or even by matching patterns within their command-line arguments. This makes it significantly more convenient for managing multiple processes or when you don't readily know the PID of the process you wish to terminate.
How does pkill work?
At its core, pkill scans the list of running processes on your system. For each process, it checks if its attributes (like name, owner, etc.) match the criteria you've provided. If a match is found, pkill sends the specified signal to that process. The default signal sent is SIGTERM (signal number 15), which requests the process to terminate gracefully, allowing it to clean up resources before exiting. However, you can explicitly specify other signals, such as SIGKILL (signal number 9), which forces the process to terminate immediately without any cleanup. This is often used as a last resort for unresponsive processes.
Common Use Cases and Examples
Killing a process by its name:
This is the most straightforward and common use of pkill. To kill all processes named 'firefox', you would use:
pkill firefoxThis command will send the SIGTERM signal to all processes whose name matches 'firefox'.
Forcibly killing a process by its name:
If a process is unresponsive to SIGTERM, you can use SIGKILL (-9) to force its termination:
pkill -9 firefoxOr, using the signal name:
pkill -KILL firefoxKilling processes owned by a specific user:
You can target processes belonging to a particular user using the -u option:
pkill -u john firefoxThis command kills all 'firefox' processes owned by the user 'john'.
Matching against the full command line:
Sometimes, the process name itself isn't specific enough, or you want to match a process based on its arguments. The -f option allows pkill to match against the entire command line used to start the process:
pkill -f "python my_script.py"This command will kill any process whose command line contains 'python my_script.py'. The quotes are important if your pattern contains spaces.
Killing processes associated with a specific terminal:
If you want to kill processes running on a particular terminal (e.g., tty1), you can use the -t option:
pkill -t tty1Listing processes that would be killed (dry run):
Before actually terminating processes, it's a good practice to see which ones would be affected. The -l option lists the process names, and -L lists the signal names:
pkill -l firefoxTo see which processes would be killed without actually killing them, you can combine pkill with grep or use its own listing capabilities. A common pattern is to list processes and then filter, but pkill itself doesn't have a direct 'dry run' flag that shows *what* it would kill without execution. However, you can often simulate this by using pgrep, which is designed for finding PIDs based on criteria, and then passing those PIDs to kill.
For example, to see the PIDs that pkill -f "my_pattern" would target, you can use:
pgrep -f "my_pattern"This will list the PIDs of processes matching the pattern, allowing you to verify before using pkill.
Understanding Signals
pkill works by sending signals. The most common ones are:
- SIGTERM (15): The default signal. Asks the process to shut down cleanly.
- SIGKILL (9): Forces the process to terminate immediately. Use with caution as it doesn't allow for saving data or cleanup.
- SIGHUP (1): Often used to tell daemons to re-read their configuration files.
You can specify signals using their number (e.g., -9) or their name (e.g., -KILL).
Important Considerations and Best Practices
- Use with Caution:
pkillis a powerful command. Killing the wrong process can lead to system instability or data loss. Always double-check your patterns. - Start with SIGTERM: Always try to use the default SIGTERM signal first. Only resort to SIGKILL (-9) if the process is completely unresponsive.
- Be Specific: Use precise names or patterns to avoid terminating unintended processes. Consider using the
-u(user) and-f(full command line) options to narrow down your targets. - Permissions: You can only kill processes that you own, unless you are the superuser (root). To kill processes owned by other users or system processes, you'll need to use
sudo. - Alternatives: For managing individual processes,
kill(using PID) is more precise. For finding processes,pgrepis useful. For interactive process management,toporhtopare excellent tools.
In summary, pkill is an indispensable command-line tool for Linux users who need an efficient way to manage and terminate processes without constantly needing to look up their PIDs. By understanding its options and using it responsibly, you can significantly streamline your system administration tasks.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- pkill(1) — Linux man pagesCC-BY-SA-4.0
- GNU grep Manual - Process MatchingGPL-3.0-or-later
- LinuxCommand.org - pkillfair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.