pidof

pidof 是Linux系統中用來查找正在運行進程的進程號(pid)的工具,功能類似pgrep和ps。

基本介紹

  • 中文名:pidof
  • 外文名:pidof
  • 特點:運行的程式的PID。
  • 實質:program as killall5;
什麼是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 //的確如此。
參數:
-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 不會出錯,但如果不是則有可能返回和給定同名的程式。
還是看實例吧。
[root@GoGo ~]# pidof nginx
1476 1475 1473 1472 1471 1470 1469 1467 1466
[root@GoGo ~]# ps -ef | 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
[root@GoGo ~]# pidof sshd
[root@GoGo ~]# ps -ef | grep sshd

相關詞條

熱門詞條

聯絡我們