pgrep - 命令

pgrep

命令格式:pgrep [選項] [模式]


選項 含義
-d <string> 指定輸出分隔符
-l PID和進程名稱
-a 列出PID和完整的命令行
-v 取反
-c 統計進程數量
-i 忽略大小寫
-n 選擇最近期啟動的(最大的進程號)
-o 最早啟動的(最小的進程號)
-P 指定父進程號
-g 指定進程組
-s 指定會話ID
-t <tty> 指定開啟進程的終端
-u <ID> 匹配有效用戶 ID
-U <ID> 匹配真實用戶 ID
-x 完全匹配
-F <file> 從文件讀取PIDs

應用

# 列出所有 sshd 的進程號,並且以 -*- 分隔
[root@localhost ~]# pgrep -ld ' -*- ' sshd
1164 sshd -*- 12879 sshd -*- 12889 sshd -*- 23358 sshd -*- 23365 sshd

# 列出最早打開的 sshd 進程
[root@localhost ~]# pgrep -lo sshd
1164 sshd

# 列出最近才打開的 sshd 進程
[root@localhost ~]# pgrep -ln sshd
23365 sshd

# 列出 pts/2 終端所有的進程,並且顯示命令
[root@localhost ~]# pgrep -lat pts/2
29172 -bash
29227 ping www.baidu.com



合上一本書,再打開一本書   -Tzyy

Tags: