pgrep多个进程名称

时间:2019-10-23 16:53:45

标签: regex linux shell grep operating-system

我想在Linux中使用“ pgrep”命令获取两个或多个进程的PID。

我们知道pgrep语法是

pgrep [options] <pattern>

这是一个假设的命令,该命令应返回两个分别名为 process1 process2 的进程的PID。

pgrep process1 OR process2 

实现上述目标需要采用什么模式?

1 个答案:

答案 0 :(得分:1)

尝试:

pgrep 'process1|process2'

示例:

 -->pgrep 'atd|cron'
1078
1093

 -->ps -eaf |grep -E 'atd|cron'
daemon    1078     1  0 Aug08 ?        00:00:00 /usr/sbin/atd -f
root      1093     1  0 Aug08 ?        00:00:19 /usr/sbin/cron -f
xxxx  14364  9597  0 11:56 pts/2    00:00:00 grep -E atd|cron
相关问题