00. 目录


文章目录


01. 命令概述

pidof命令​用于查找指定名称的进程的进程号。

02. 命令格式

格式:pidof [选项] [参数]

03. 常用选项

-s:仅返回一个进程号;
-c:仅显示具有相同“root”目录的进程;
-x:显示由脚本开启的进程;
-o:指定不显示的进程ID。

04. 参考示例

4.1 查看指定进程的进程号

[deng@itcast ~]$ pidof bash
91509 86546 698
[deng@itcast ~]$

4.2 仅显示一个进程号

[deng@itcast ~]$ pidof -s bash
91509
[deng@itcast ~]$

4.3 显示由脚本开启的进程

[deng@itcast ~]$ pidof -x /bin/bash
91509 86546
[deng@itcast ~]$

4.4 显示具有相同根目录的进程

[deng@itcast ~]$ pidof -c bash
91509 86546 698
[deng@itcast ~]$

4.5 指定不显示进程ID

[deng@itcast ~]$ pidof bash
91509 86546 698
[deng@itcast ~]$ pidof -o 698 bash
91509 86546
[deng@itcast ~]$

05. 附录

参考:​​【Linux】一步一步学Linux系列教程汇总​