pidof---找寻PID

pidof---找寻pid

1.根据守护进程找到pid

[root@localhost ~]# pidof sshd
2542 1622
[root@localhost ~]# ps -ef | grep sshd
root       1622      1  0 15:47 ?        00:00:00 /usr/sbin/sshd -D
root       2542   1622  0 15:52 ?        00:00:00 sshd: root@pts/0
root       2569   2546  0 15:53 pts/0    00:00:00 grep --color=auto sshd

2.找出后台shell脚本的pid

[root@localhost ~]# vim sleep.sh
#!/bin/bash
sleep 1000m

"sleep.sh" [New] 3L, 25C written                                                                                                                         
[root@localhost ~]# chmod a+x sleep.sh 
[root@localhost ~]# ./sleep.sh &
[1] 2572
[root@localhost ~]# pidof sleep.sh 
[root@localhost ~]# pidof -x  sleep.sh         # 要加-x 参数
2572
[root@localhost ~]# ps -ef | grep sleep.sh 
root       2572   2546  0 15:55 pts/0    00:00:00 /bin/bash ./sleep.sh
root       2577   2546  0 15:55 pts/0    00:00:00 grep --color=auto sleep.sh

3.-o 忽略我们指定的PID

[root@localhost ~]# pidof sshd
2542 1622
[root@localhost ~]# pidof sshd -o 1622
2542
posted @ 2019-11-11 21:03  Noob52037  阅读(133)  评论(0编辑  收藏  举报