Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux pidof command

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use the Linux pidof command". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

What is the pidof command?

The copy code is as follows:

# explanation in man pidof:

Pidof-find the process idof a running program.

Pidof- is used to find the pid of a running program.

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. Parameters of the pidof command

-s means only 1 pid is returned

-x indicates the pid that simultaneously returns the shell running the given program.

-o means to tell piod to ignore the pid given later, and 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 pidof, 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 a fullpath, pidof will not make an error, but if it is not, it is possible to return a program with the same name as the given program.

3. Examples of using pidof command

The copy code is as follows:

[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

This is the end of "how to use Linux pidof commands". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report