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

Quick Answer: The `pkill` command in Linux is used to send signals to processes based on their name or other attributes. It's a powerful tool for terminating processes without needing to know their exact process ID (PID). You can use it to kill processes by name, user, terminal, or even by matching a pattern in the command line.

Key Facts

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 firefox

This 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 firefox

Or, using the signal name:

pkill -KILL firefox

Killing processes owned by a specific user:

You can target processes belonging to a particular user using the -u option:

pkill -u john firefox

This 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 tty1

Listing 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 firefox

To 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:

You can specify signals using their number (e.g., -9) or their name (e.g., -KILL).

Important Considerations and Best Practices

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.

Sources

  1. pkill(1) — Linux man pagesCC-BY-SA-4.0
  2. GNU grep Manual - Process MatchingGPL-3.0-or-later
  3. LinuxCommand.org - pkillfair-use

Missing an answer?

Suggest a question and we'll generate an answer for it.