How to Use the pkill Command in Linux

By 

Updated on

5 min read

Linux pkill

pkill is a command-line utility that sends signals to the processes of a running program based on given criteria. The processes can be specified by their full or partial names, a user running the process, or other attributes.

The pkill command is part of the procps (or procps-ng) package, which is pre-installed on nearly all Linux distributions. pkill and pgrep use the same matching rules; pgrep lists matching processes, while pkill sends signals to them.

How to Use the pkill Command

The syntax for the pkill command is as follows:

txt
pkill [OPTIONS] <PATTERN>

The matching <PATTERN> is specified using extended regular expressions.

When invoked without any option, pkill sends the 15 (TERM) signal to the PIDs of all running programs that match the given name. For example, to gracefully stop all Firefox processes, you would run:

Terminal
pkill firefox

The command returns 0 when at least one running process matches the requested name. Otherwise, the exit code is 1. This can be useful when writing shell scripts.

Before using a broad pattern, preview matches with pgrep -a pattern.

To send a different signal to the matched processes, invoke the pkill command with the --signal option, followed by either the numeric or the symbolic signal name. Another way to send a signal is to run pkill followed by the signal name or number prefixed by a hyphen (-).

Use the kill -l command to list all available signals.

The most commonly used signals are:

  • 1 (HUP) - Reload configuration for daemons that support it.
  • 9 (KILL) - Force immediate termination. Use it as a last resort.
  • 15 (TERM) - Gracefully stop a process. This is the default signal.

Signals can be specified in three different ways:

  • Using a number, such as -1
  • With the SIG prefix, such as -SIGHUP
  • Without the SIG prefix, such as -HUP

For example, to reload the Nginx processes you would run:

Terminal
pkill -HUP nginx

pkill uses regular expressions to match the process names. It is always a good idea to use the pgrep command to print the matched processes before sending signals to them. For instance, to list all processes that contain “ssh” in their names:

Terminal
pgrep -a ssh
output
1039 sshd: /usr/sbin/sshd -D
2257 ssh-agent -s
6850 ssh user@example.com
31279 ssh-agent -s

If you want to send a signal only to the processes whose names are exactly as the search pattern, use the -x option:

Terminal
pkill -x ssh

You can also use regular expression anchors:

Terminal
pkill '^ssh$'
Info
The caret (^) character matches at the beginning of the string, and the dollar $ at the end.

By default, pkill matches only against the process name. When the -f option is used, the command matches against full argument lists. If the command contains spaces, quote the entire command:

Terminal
pgrep -af "ping 8.8.8.8"
pkill -f "ping 8.8.8.8"

Use -9 only if the process does not stop after the normal TERM signal.

Use the -u option to tell pkill to match processes being run by a given user:

Terminal
pkill -u mark firefox

To specify multiple users, separate their names with commas:

Terminal
pkill -u mark,danny firefox

Running pkill -u mark without a pattern can signal every process owned by mark, including shells and background jobs.

You can also combine options and search patterns. For example, to send KILL signal to all processes that run under user “mark” and contain “gnome” in their names:

Terminal
pkill -9 -u mark gnome

To display only the least recently (oldest) or the most recently (newest) started processes, use the -n (for newest) or the -o (for oldest) option.

For example, to kill the most recently created screen :

Terminal
pkill -9 -n screen

Case-Insensitive Matching

By default, pkill performs case-sensitive pattern matching. To match process names regardless of case, use the -i option:

Terminal
pkill -i firefox

This will match “firefox”, “Firefox”, “FIREFOX”, and any other case variation.

Killing Processes by Terminal

The -t option allows you to send signals to processes running on a specific terminal:

Terminal
pkill -t pts/1

This kills all processes associated with terminal pts/1. You can find terminal names using the who or w command.

Counting Matched Processes

To see how many processes match a pattern without sending any signal, use pgrep with the -c option:

Terminal
pgrep -c firefox
output
3

This shows 3 Firefox processes running.

pkill vs kill vs killall

  • kill - Sends signals to processes by PID. You need to know the exact process ID.
  • pkill - Sends signals to processes by name pattern. Supports regex and various filters.
  • killall - Sends signals to all processes with an exact name match. Simpler than pkill but less flexible.

Use kill when you know the exact PID, pkill when you need pattern matching or filters, and killall for simple exact name matches. For a task-focused walkthrough that puts all three together, see how to kill a process in Linux .

Quick Reference

For a printable quick reference, see the pkill cheatsheet .

TaskCommand
Kill by namepkill firefox
Force kill by namepkill -9 firefox
Reload processpkill -HUP nginx
Kill by user and namepkill -u username process_name
Kill by full commandpkill -f "ping 8.8.8.8"
Case insensitivepkill -i Firefox
Kill by terminalpkill -t pts/1
Kill newest processpkill -n process_name
Kill oldest processpkill -o process_name
List matches firstpgrep -a pattern

Conclusion

The pkill command is useful when you need to signal processes by name, user, terminal, or full command pattern. Preview matches with pgrep , use exact or scoped patterns when possible, and use kill when you already know the exact PID.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page