linux pidof用法,科技常识:Linux pidof命令使用总结

本文介绍了Linux中的pidof命令,用于查找正在运行的程序的进程ID(PID)。pidof实际上是killall5命令的链接。文章详细阐述了pidof的参数,如-s参数仅返回一个PID,-x参数返回运行给定程序的shell的PID,-o参数忽略指定的PID。通过实例展示了如何使用pidof查找nginx和sshd的PID,并与ps命令结合使用进行验证。
摘要由CSDN通过智能技术生成

今天小编跟大家讲解下有关Linux pidof命令使用总结 ,相信小伙伴们对这个话题应该也很关注吧,小编也收集到了有关Linux pidof命令使用总结 的相关资料,希望小伙伴会喜欢也能够帮助大家。

一、什么是pidof命令?复制代码 代码如下:#man pidof中的解释:pidof ― find the process ID of a running program.pidofC用于查找一个运行的程序的PID。pidof is actually the same program as killall5;[[email protected] ~]# ls -l /sbin/pidoflrwxrwxrwx. 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 itis possible that it returns pids of running programs that happen to have the same name as the program you're after but areactually other programs.如果 是一个 fullpath 则 pidof 不会出错,但如果不是则有可能返回和给定同名的程序。

三、pidof命令使用实例复制代码 代码如下:[[email protected] ~]# pidof nginx1476 1475 1473 1472 1471 1470 1469 1467 1466[[email protected] ~]# ps -ef | grep nginxnginx 1450 1449 0 20:16 ? 00:00:00 php-fpm: pool wwwnginx 1451 1449 0 20:16 ? 00:00:00 php-fpm: pool wwwnginx 1452 1449 0 20:16 ? 00:00:00 php-fpm: pool wwwnginx 1453 1449 0 20:16 ? 00:00:00 php-fpm: pool wwwnginx 1454 1449 0 20:16 ? 00:00:00 php-fpm: pool wwwroot 1466 1 0 20:16 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.confnginx 1467 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1469 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1470 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1471 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1472 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1473 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1475 1466 0 20:16 ? 00:00:00 nginx: worker processnginx 1476 1466 0 20:16 ? 00:00:00 nginx: worker processroot 2234 2141 0 20:24 pts/1 00:00:00 grep nginx[[email protected] ~]# ps -ef | grep nginx | awk '{print $2}'145014511452145314541466146714691470147114721473147514762237[[email protected] ~]# pidof -s nginx1476[[email protected] ~]# pidof sshd2139 1163[[email protected] ~]# ps -ef | grep sshdroot 1163 1 0 20:16 ? 00:00:00 /usr/sbin/sshdroot 2139 1163 0 20:20 ? 00:00:00 sshd: [email protected]/1

来源:爱蒂网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值