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

What is the specific use of the Linux system command pidof

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

Share

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

This article is to share with you about the specific use of the Linux system command pidof, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.

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, and we will introduce options common to both implementations.

The syntax of the pidof command is:

Pidof [OPTIONS] PROGRAM_NAME

Reference: the pidof command _ Linux pidof command uses the detailed description: find the process number ID number of the process with the specified name.

This command takes zero or more names as parameters, but typically you pass only one name to pidof.

When called without any option, pidof prints the PID of all running programs that match the given name. For example, to find the PID of a SSH server, run:

Pidof sshd

If there is a running process with a name that matches sshd, its PID will be displayed on the screen, and if no match is found, the output will be empty:

4382 4368 811

Pidof returns 0 when at least one running program matches the name of the request, otherwise, the exit code is 1, which 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 matching running programs are displayed, using 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

Example 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.

Assuming that the Firefox browser is not responding and you need to terminate the Firefox process, first, use pidof to find the PID:

Pidof firefox

This command prints all Firefox processes:

2551 2514 1963 1856 1771

Once it is known that Firefox has processed PID, a SEGTERM signal is sent to terminate all PID:

Sudo kill-9 2551 2514 1963 1856 1771

You can also use the command to replace the expression $(…) Terminate the program in a command:

Sudo kill-9 $(pidof firefox).

What are the versions of Linux? the versions of Linux are Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and so on. Among them, Deepin is one of the best-developed Linux distributions in China; UbuntuKylin is a derivative release based on Ubuntu; Manjaro is a Linux release based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP's easy-to-use; Ubuntu is the Linux operating system based on desktop applications.

The above is the specific use of the Linux system command pidof, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.

Share To

Development

Wechat

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

12
Report