2

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

我们知道 pgrep 语法是

pgrep [options] <pattern>

这是一个假设的命令,它应该返回两个进程的 PID,其名称分别为process1process2

pgrep process1 OR process2 

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

4

1 回答 1

4

尝试:

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
于 2019-10-23T16:57:08.513 回答