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