1. 程式人生 > 其它 >linux 系統中pgrep命令

linux 系統中pgrep命令

linux系統中pgrep用於查詢程序

1、查詢與命令相關的程序

[root@centos79 test]# pgrep sort
[root@centos79 test]#

啟動一個sort命令測試:

[root@centos79 test]# seq -f test%03g 100000000| sort | uniq -c
[root@centos79 test]# pgrep sort  ## 另外一個終端
18521
[root@centos79 test]# pgrep -l sort    ## -l 列出具體命令
18521 sort

2、-u查詢與使用者相關的程序

[root@centos79 test]# pgrep -u root | head
1 2 4 6 7 8 9 10 11 12
[root@centos79 test]# pgrep -l -u root | head
1 systemd
2 kthreadd
4 kworker/0:0H
6 ksoftirqd/0
7 migration/0
8 rcu_bh
9 rcu_sched
10 lru-add-drain
11 watchdog/0
12 watchdog/1

3、-l ,-u + 命令關鍵字 查詢與使用者指定命令相關的進位制

[root@centos79 test]# pgrep -l -u root | tail
18314 kworker/0:0
18328 kworker/1
:5 18329 kworker/1:6 18421 kworker/3:1 18489 kworker/3:0 18491 kworker/u256:2 18502 kworker/0:2 18568 kworker/0:1 18577 sleep 18584 tail

利用root啟動一個sort命令:

[root@centos79 test]# pgrep -l -u root sort

在另一個終端測試查詢:

[root@centos79 test]# pgrep -l -u root sort
18612 sort