就我而言,我有运行 nagios 服务的 nagios 服务器。但是当我跑步时ps -ef | grep nagios
,我可以看到:
nagios 3361 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3363 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3364 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3368 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3374 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3382 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3384 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3389 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3393 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3397 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3404 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3408 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3414 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 3416 13524 0 15:42 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios进程的实例也是如此。请帮忙。
答案1
您可以使用 pgrep。看man pgrep
$pgrep nagios #list all the process ids
用于计数:
$pgrep nagios | wc -l
答案2
您也可以使用 pidof。查看man pidof
或info pidof
.例如,在我当前的设置上运行它会显示以下内容:
pidof chrome
3946 3202 3194 3175 3154 3137 3114 3103 3077 3024 3019 3012 3005 2998
正如@Ijaz 所建议的,您还可以通过以下方式获取计数:
pidof chrome | wc -l
14