How to Use the pkill Command in Linux

By 

Updated on

4 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 is basically a wrapper around the pgrep program that only prints a list of matching processes.

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 -15 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.

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): to reload a process.
  • 9 (KILL): to kill a process.
  • 15 (TERM): to gracefully stop a process.

Signals can be specified in three different ways:

  • using a number (e.g., -1)
  • with the “SIG” prefix (e.g., -SIGHUP)
  • without the “SIG” prefix (e.g., -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 -l ssh
output
1039 sshd
2257 ssh-agent
6850 ssh
31279 ssh-agent

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

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
pkill -9 -f "ping 8.8.8.8"

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

Terminal
pkill -u mark

To specify multiple users, separate their names with commas:

Terminal
pkill -u mark,danny

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.

Quick Reference

TaskCommand
Kill by namepkill firefox
Force kill by namepkill -9 firefox
Reload processpkill -HUP nginx
Kill by userpkill -u username
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 -l pattern

Conclusion

We covered the pkill command including sending signals by process name, user, terminal, and using pattern matching.

For more information, check the pkill man page . You may also want to look at related commands like kill , pgrep , and ps .

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