Linux pidof命令使用总结

 更新时间:2014年03月16日 16:39:53   作者:  
今天GoFace给大家介绍linux pidof命令的用法,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 you're 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

相关文章

  • 阿里云云服务器Linux系统挂载数据盘图文教程

    阿里云云服务器Linux系统挂载数据盘图文教程

    这篇文章主要介绍了阿里云云服务器Linux系统挂载数据盘图文教程,阿里云服务器一般需要购买额外的数据盘,本文就讲解如何挂载使用额外的数据盘,需要的朋友可以参考下
    2014-09-09
  • apache伪静态与iis伪静态规则与配置区别介绍

    apache伪静态与iis伪静态规则与配置区别介绍

    本文章来总结一下关于apache伪静态与iis伪静态区别介绍,主要讲到了一些规则的问题与配置区别,以后大家就可以直接在iis伪静态转换apache,反之也很简单哦,需要了解的碰可以参考下
    2012-12-12
  • linux让程序开机自动运行最简单的方法

    linux让程序开机自动运行最简单的方法

    在本篇文章里小编给大家整理的是一篇关于linux让程序开机自动运行最简单的方法以及相关代码,需要的朋友们学习下。
    2019-11-11
  • 手把手教你在腾讯云上搭建hive3.1.2的方法

    手把手教你在腾讯云上搭建hive3.1.2的方法

    这篇文章主要介绍了手把手教你在腾讯云上搭建hive3.1.2的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-07-07
  • linux vps服务器进程kswapd0与events/0消耗大量CPU的问题

    linux vps服务器进程kswapd0与events/0消耗大量CPU的问题

    使用了阿里云的vps服务器网站宕了两次机,发工单给阿里云,发现原因是服务器的CPU 100%了,这也是vps的弊端,内容给的相对小
    2014-03-03
  • 在 CentOS 8/RHEL 8 上安装和使用 Cockpit的方法

    在 CentOS 8/RHEL 8 上安装和使用 Cockpit的方法

    Cockpit 是一个基于 Web 的服务器管理工具,可用于 CentOS 和 RHEL 系统。最近发布的 CentOS 8 和 RHEL 8,其中 cockpit 是默认的服务器管理工具。这篇文章主要介绍了在 CentOS 8/RHEL 8 上安装和使用 Cockpit的方法,需要的朋友可以参考下
    2019-10-10
  • Linux系统创建TCP连接流程介绍

    Linux系统创建TCP连接流程介绍

    大家好,本篇文章主要讲的是Linux系统创建TCP连接流程,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下哦,方便下次浏览
    2021-12-12
  • Apache支持 shtml和include文件解析

    Apache支持 shtml和include文件解析

    这篇文章主要介绍了Apache支持 shtml和include文件解析的相关资料,需要的朋友可以参考下
    2015-07-07
  • Linux用户自定义at、cron计划任务执行的方法

    Linux用户自定义at、cron计划任务执行的方法

    今天小编就为大家分享一篇Linux用户自定义at、cron计划任务执行的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-07-07
  • 详解Linux系统无法上网解决方案

    详解Linux系统无法上网解决方案

    本篇文章主要介绍了详解Linux系统无法上网解决方案,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-06-06

最新评论