Learn more about the Pidof command in the Linux Terminal

pidof It is a command-line utility that allows you to find the process ID of a running program.

In this article we will explain how to use commands pidof Linux.

How to use the pidof command

There are various applications pidof For Red Hat and Debian distributions. In a Red Hat distribution, the pidof command is part of the package procps-ngWhile in Debian, it is part of sysvinit-utils. We’ll cover options common to both apps.

Syntax for commands pidof They are as follows:


When called without any options, pidof will print the PIDs of all running programs that match the name specified. For example, to find the PID of your SSH server, you could run:

pidof sshd

If a process is running with the corresponding name sshd, Their PID will be displayed on the screen. If no matches are found, the result is blank.

4332 4328 881

Pidof return 0 When at least one program matches the requested name. Otherwise, the exit code is 1. This output is useful when used for analysis in shell scripts.

To ensure that only the product ID is displayed for the program that you are looking for, use the full pathname of the program as an argument. For example, if you have two programs running with the same name that are in two different directories, pidof will display the PIDs for both programs that are currently running.

By default, all PIDs of the corresponding running programs are displayed. Use the options -s To force pidof to display only one PID:

pidof -s nama_program

Selection -o It allows you to exclude processes with the specified PID from the command output:

pidof -o pid nama_program

when pidof Called with options -o, You can use PID %PPID Which represents a shell summon or a shell text.

To return the process ID only for processes running in the same root directory, use the option -c.

This option only works if pidof is running as the root or sudo user:

pidof -c pid program_name

Example of using the Pidof command

The following example shows how to use the pidof command with the command kill To terminate the program.

Suppose your Firefox browser has become unresponsive, and you need to end the Firefox process. First, find PID, along with pidof:

pidof firefox

The command will print all Firefox processes:

2551 2514 1963 1856 1771

Once you know Firefox is processing PIDs, send a signal SEGTERM To stop everything:

sudo kill -9 2551 2514 1963 1856 1771

You can also use the expression to replace the command with $(...)To end a program with one command:

sudo kill -9 $(pidof firefox)


The pidof command is used to find out the PID of a specific program that is running.

pidof is a simple command that doesn’t have many options. Usually you will just call pidof with the name of the program you are looking for.


Source link

Leave a Reply

Your email address will not be published. Required fields are marked *