简体   繁体   English

pgrep 多个进程名称

[英]pgrep multiple process names

I want to get PIDs of two or more processes using "pgrep" command in Linux.我想在 Linux 中使用“pgrep”命令获取两个或多个进程的 PID。

As we know pgrep syntax is我们知道 pgrep 语法是

pgrep [options] <pattern>

Here is a hypothetical command which should return PIDs of two processes whose names are process1 and process2 respectively.这是一个假设的命令,它应该返回两个进程的 PID,其名称分别为process1process2

pgrep process1 OR process2 

What should be the pattern that needs to be used to achieve the above?实现上述目标需要使用什么模式?

Try:尝试:

pgrep 'process1|process2'

Example:例子:

 -->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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM