fbpx pgrep Command in Linux: Find Processes by Name | Certificação Linux

pgrep Command in Linux: Find Processes by Name and Return PID

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
pgrep Command in Linux: Find Processes by Name and Return PID
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The pgrep command in 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 PIDs of nginx processes:

$ pgrep nginx279912799327994

To list all PIDs of processes owned by root:

$ pgrep –u root123

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

# pgrep --signal 1 nginx279912799327994

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

$ pgrep -u root named

Makes the syslog process reread its configuration file:

$ pkill -HUP syslogd

Shows detailed information of 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 use less CPU:

$ renice +4 $(pgrep firefox)

Difference between pgrep and killall

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

pgrep works similarly to pkill.

Learn much more about Linux in our online course. You can enroll 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

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp