The Linux pidof command USES summaries
- 2020-05-09 19:44:20
- OfStack
1. What is the pidof command?
#man pidof Explanation:
pidof - find the process ID of a running program.
pidof To find 1 Of a running program 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 // That's true.
2. Arguments to the pidof command
-s means only one pid is returned
-x means pid of shell running the given program is returned at the same time
-o means tell piod means ignore the given pid, you can use multiple -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.
If it is 1 fullpath, pidof will not fail, but if it is not, it is possible to return a program with the given name.
3. Use examples of the pidof command
[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