Linux command explanation: Pgrep command

Source: Internet
Author: User

Reprint: http://www.th7.cn/system/lin/201311/46742.shtml

Objective

You often want to see information about the process, including whether the process has died out, and pgrep to get information about the process being dispatched. Pgrep finds a matching process by matching its program name

Important Options
-L Displays both the process name and the PID
-O When multiple processes are matched, the one with the smallest process number is displayed
-N When matching multiple processes, the one with the largest process number is displayed
Note: The larger the process number does not necessarily mean that the process starts at a later time

Instructions for use
View process information for the specified name

PID only appears by default

12345         [[email protected] ~] # pgrep ssh         3686         7907         8815          12874

    display both PID and processname: –l

12345          [[email protected] ~] # pgrep -l sshd         3686 sshd          7907 sshd         8815 sshd         12874 sshd

-O When multiple processes are matched, the one with the smallest process number is displayed

1234567        [[email protected] ~]# pgrep -l sshd       3686 sshd       7907 sshd       8815 sshd       12874 sshd       [[email protected] ~]# pgrep -l -o  sshd       3686 sshd

-N When matching multiple processes, the one with the largest process number is displayed

12        [[email protected] ~]# pgrep -l -n sshd       12874 sshd

Special Instructions

1) pgrep equivalent to Ps-eo pid,cmd | awk ' {print $1,$2} ' | grep KeyWord

12        [[email protected] ~]# ps -eo pid,cmd | awk ‘{print $1,$2}‘  | grep init       [[email protected] ~]# pgrep init

2) For example, 1), Pgrep looks for the program name, excluding its parameters

As below, the parameters include the parameters to be looked up, and the program name is not included, all are not found.

12345        [[email protected] ~]# ps axu | grep name       root     13298  0.0  0.3   5436  1000 pts/4S    05:52   0:00 sh name.sh       root     13313  0.0  0.2   4876   672 pts/4R+   05:53   0:00 grepname       [[email protected] ~]# pgrep name       [[email protected] ~]#

Summarize

Linux command explanation: Pgrep command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.