Skip to content

pgrep command on Linux (find files)

The pgrep command on Linux allows you to search for expressions in the list of running processes and returns the PID of the process in question. It also allows signals to be sent to those processes listed in the search expression.

In this example, pgrep lists all the PIDs of the nginx processes:

$ pgrep nginx 27991 27993 27994

To list all the PIDs of the processes whose owner is root:

$ pgrep —u root 1 2 3

To send a signal to the processes, simply use the —signal option and the signal number. In this example, the SIGHUP signal is sent to nginx:

# pgrep --signal 1 nginx 27991 27993 27994

Shows the PID of processes whose owner is the root and have a named name:

$ pgrep -u root named

Make the syslog process reread your configuration file:

$ pill -HUP syslog

Shows detailed information about all processes connected to the xterm terminal:

$ ps -fp$ (pgrep -d, -x xterm)

You can combine the use of pgrep with shell expansions, as in the example that makes Firefox consume less CPU:

$ renice +4 $ (pgrep firefox)

Difference between pgrep and killall

The pgrep command can read the list of processes based on the name or a series of attributes, while kill only searches for the process name.

Pgrep works similar to pkill.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share