linux 系统中pgrep命令

时间:2021-07-21
本文章向大家介绍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

原文地址:https://www.cnblogs.com/liujiaxin2018/p/15039036.html