pidof --- look for PID

pidof --- look for pid

1. Locate the pid according daemon

[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. Find pid background shell script

[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 ignore our designated PID

[root@localhost ~]# pidof sshd
2542 1622
[root@localhost ~]# pidof sshd -o 1622
2542

Guess you like

Origin www.cnblogs.com/zhoujun007/p/11838465.html