小知识:Linux pidof命令使用总结

一、什么是pidof命令?

复制代码 代码如下:

#man pidof中的解释:

pidof — find the process ID of a running program.

pidof–用于查找一个运行的程序的PID。

pidof is actually the same program as killall5;

[root@GoGo ~]# ls -l /sbin/pidof

lrwxrwxrwx. 1 root root 8 Aug 25 00:40 /sbin/pidof -> killall5 //的确如此。

二、pidof命令的参数

-s 表示只返回1个 pid

-x 表示同时返回运行给定程序的 shell 的 pid

-o 表示告诉 piod 表示忽略后面给定的 pid ,可以使用多个 -o 。

pidof is simply a (symbolic) link to the killall5 program, which should also be located in /sbin.

When pidof is invoked with a full pathname to the program it should find the pid of, it is reasonably safe. Otherwise it

is possible that it returns pids of running programs that happen to have the same name as the program youre after but are

actually other programs.

如果 是一个 fullpath 则 pidof 不会出错,但如果不是则有可能返回和给定同名的程序。

三、pidof命令使用实例

复制代码 代码如下:

[root@GoGo ~]# pidof nginx

1476 1475 1473 1472 1471 1470 1469 1467 1466

[root@GoGo ~]# ps -ef | grep nginx

nginx     1450  1449  0 20:16 ?        00:00:00 php-fpm: pool www

nginx     1451  1449  0 20:16 ?        00:00:00 php-fpm: pool www

nginx     1452  1449  0 20:16 ?        00:00:00 php-fpm: pool www

nginx     1453  1449  0 20:16 ?        00:00:00 php-fpm: pool www

nginx     1454  1449  0 20:16 ?        00:00:00 php-fpm: pool www

root      1466     1  0 20:16 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

nginx     1467  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1469  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1470  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1471  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1472  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1473  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1475  1466  0 20:16 ?        00:00:00 nginx: worker process

nginx     1476  1466  0 20:16 ?        00:00:00 nginx: worker process

root      2234  2141  0 20:24 pts/1    00:00:00 grep nginx

[root@GoGo ~]# ps -ef | grep nginx | awk {print $2}

1450

1451

1452

1453

1454

1466

1467

1469

1470

1471

1472

1473

1475

1476

2237

[root@GoGo ~]# pidof -s nginx

1476

[root@GoGo ~]# pidof sshd

2139 1163

[root@GoGo ~]# ps -ef | grep sshd

root      1163     1  0 20:16 ?        00:00:00 /usr/sbin/sshd

root      2139  1163  0 20:20 ?        00:00:00 sshd: root@pts/1
声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:LINUX中NGINX反向代理下的TOMCAT集群(详解)

2023-4-24 4:10:15

建站知识

小知识:nginx超时设置详细介绍

2023-4-24 4:19:32

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索