How to Use the PGrep & PKill Commands

The easiest way to kill processes using Linux

There are lots of different ways to kill processes using Linux. For instance, we also have a guide showing the 5 ways to kill a Linux program and a guide on how to kill any application with a single command.

In this guide, we will be expanding on the usage and available switches for the PGrep and the PKill command.


For those familiar with the Linux command line, grep command should be familiar. It filters through text to find a specific word or set of characters. PGrep is similar, but for system processes. You can use it to find the process number of a problematic program that you want to stop.

Say Firefox isn't responding, and you need to shut it down. Use PGrep to search for "firefox," and you'll get the process or processes that it's running.

pgrep firefox

Linux PGrep

This isn't super useful most of the time because PKill actually can kill a process with the application name. However, if you don't know or remember the exact name, PGrep can match part of it. So, to use the Firefox example, you could search for "fire" and get the processes for Firefox. You'll get any other processes with "fire" in the name too, so you need to be careful, but there usually isn't any overlap, if you're careful what you search.

pgrep fire

The results will come out the same way, and you'll be able to use the process number to stop the stalled application.


The PKill command allows you to kill a program simply by specifying the name. For instance, if you want to kill all open terminals with the same process ID you can type the following:

pkill term

You can return a count of the number of processes killed by supplying the -c switch as follows:

pkill -c

The output will simply be the number of processes killed.

Linux PKill number

To kill all the processes for a particular user run the following command:

pkill -u

To find the effective user id for a user uses the ID command as follows:

id -u

For example:

id -u gary

You can also kill all the processes for a particular user using the real user ID as follows:

pkill -U

The real user ID is the ID of the user running the process. In most cases, it will be the same as the effective user but if the process was run using elevated privileges then the real user ID of the person running the command and the effective user will be different.

To find the real user ID use the following command:

id -ru

You can also kill all the programs in a particular group by using the following commands:

pkill -g
pkill -G