In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to use the Linux pidof command", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use the Linux pidof command" can help you solve your doubts.
Pidof is a tool used in Linux systems to find the process number (pid) of a running process, which is similar to pgrep and ps. The pidof command is used to find the process number id number of the process with the specified name.
How to use the pidof command
For distributions based on Red Hat and Debian, there are different implementations of pidof. In the Red Hat distribution, the pidof command is part of the procps-ng package, while on Debian, it is part of sysvinit-utils. We will introduce the options common to both implementations.
The syntax of the pidof command is:
Pidof [option] Program name
This command takes zero or more names as parameters, but typically you pass only one name to pidof.
When called without any options, pidof prints the PID of all running programs that match the given name. For example, to find the PID of vim, run:
[linuxidc@linux:~/www.linuxidc.com] $pidof vim4942
If there is a running process with a name that matches sshd, its PID is displayed on the screen. If no match is found, the output will be empty.
Output
4942
Pidof returns 0 when at least one running program matches the name of the request. Otherwise, the exit code is 1. This is useful when used in shell scripts.
To ensure that only the PID of the program you want to search is displayed, use the full pathname of the program as a parameter. For example, if you have two running programs with the same name in two different directories, pidof will display the PID of both running programs.
By default, all PID of the running program that match is displayed. Use the-s option to force pidof to display only one PID:
$pidof-s program name
The-o option allows you to exclude processes with a given PID from the command output:
$pidof-o pid program name
When pidof is called with the-o option, a special PID named% PPID can be used to indicate that the Shell program or Shell script is called.
To return only the PID of processes running with the same root directory, use the-c option.
This option applies only to pidof running as root or sudo:
$pidof-c pid program name
Examples of usage of the pidof command
The following example shows how to use a combination of the pidof command and the kill command to terminate a program.
Assume that the Firefox browser is unresponsive and you need to terminate the Firefox process. First, use pidof to find PID:
[linuxidc@linux:~/www.linuxidc.com] $pidof firefox
This command prints all Firefox processes:
Output
5231 5207 5166 5131 5090
Once it is known that Firefox has processed PID, a SEGTERM signal is sent to terminate all PID:
[linuxidc@linux:~/www.linuxidc.com] $sudo kill-9 5231 5207 5166 5131 5090
You can also use commands to replace expressions (…) To terminate the program with a command:
[linuxidc@linux:~/www.linuxidc.com] (pidof firefox)
Read here, this "how to use Linux pidof command" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.