Pgrep Command in Linux | mstvlife - MS TV Life.COM

Pgrep Command in Linux | mstvlife

Pgrep Command in Linux | mstvlife

This article covers the basics of the Linux pgrep command.

pgrep is an order line utility that permits you to discover the procedure IDs of a running project dependent on given criteria. It very well may be a full or halfway procedure name, a client running the procedure, or different properties.

How to Install Gradle on Debian 10

The pgrep command is a part of the procps (or procps-ng) package, which is pre-installed on nearly all Linux distributions.

How to Use the pgrep Command #

The syntax for the pgrep command is as follows:


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

When conjured with no alternative, pgrep shows the PIDs of every single running project that coordinate with the given name. For instance, to discover the PID of the SSH server, you would run:

pgrep ssh

In the event that there are running procedures with names coordinating “ssh”, their PIDs will be shown on the screen. On the off chance that no matches are discovered, the yield is vacant.


The order returns 0 when at any rate one running procedure coordinates the mentioned name. Something else, the leave code is 1. This can be valuable when utilized in shell contents.

How to Install and Use PHP Composer on CentOS 8

If you want to send signals to the matched processes use pkill. This command is a wrapper around the pkill, and uses same options and pattern matching.

pgrep prints each ID pairing process on a new line. The -d option allows you to specify a different delimiter. For example, whether to use a delimiter space, enter:

pgrep ssh -d' '
1039 2257 6850 31279

The -l option tells pgrep to show the process name along with its ID:

pgrep ssh -l

pgrep utilizes customary articulations to play out the hunt activity and will list all procedures that contain “ssh” in their names:

1039 sshd
2257 ssh-agent
6850 ssh
31279 ssh-agent

In the event that you need to coordinate just the procedures which names are actually as the inquiry design, you would utilize:

pgrep '^ssh
6850 ssh

The caret (^) character matches at the beginning of the string, and the dollar $ at the end.

By default, pgrep matches only against the process name. When -f option is used the command matches against full argument lists.

pgrep -f ssh

Use the -u option to tell pgrep to display processes being run by a given user :

pgrep -u root

To specify multiple users, separate their names with commas:

pgrep -u root,mark

You can likewise consolidate choices and search designs. For instance to print all procedures and their names that run under client “mark” and contains “elf” in their names you would type:

Find out how to Setup FTP Server with VSFTPD on CentOS 8

pgrep -l -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 find the newest process started by the user “mark”, you would enter:

pgrep -lnu mark

As you can see from the example above, you can also combine the options without a space between them and with a single dash.

To turn around the coordinating, for example to show just procedures that don’t coordinate the given criteria, utilize the – v alternative. The accompanying order will print all procedures that are not being controlled by client “mark”:

pgrep -v -u mark

The -c option tells pgrep to print only the count of the matching processes. For example to find the processes that run as user “mark”, enter:

pgrep -c -u mark

Conclusion #

The pgrep order is utilized to discover the PIDs of a running project dependent on various criteria.

How To Set or Change Timezone on CentOS 8

For more information about pgrep command, visit the pgrep man page or type man pgrep in your terminal.

If you have any questions or feedback, feel free to leave a comment.

Copy link
Powered by Social Snap