Pidof Command in Linux Terminal with example

Pidof Command in Linux Terminal

In the Linux, the pidof is a command-line tool that is used to find the process ID of a running program. In this article, we will going to show you how to use the pidof command in Linux terminal. If you want to learn about Pidof Command in Linux then this post is ideal for you.

Linux is an operating system, like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).

How to Use the pidof Command

In the Linux, the basic syntax of the Pidof command is show as below:

pidof [options] program_name

The Pidof command can accept one or more program names as an arguments but basically it is used for only one program name to get pidof.

If you run the Pidof command without any option, pidof command will display the process IDs of all running programs that match with the given name.

For an example, Run the below command :

$ pidof bash

When you run the above command, it will print the Process IDs of all running programs which matches with bash name. If no matching names are found then the output will be empty.


To get only one process ID of a program

By default when you run the Pidof command without any option, pidof command will display the process IDs of all running programs that match with the given name . So Use the -s option to force pidof command to display only one process ID.

$ pidof -s program_name

To exclude a process with a given PID from the command output

Use the -o option to exclude a process with a given PID from the command output, simply run the below command to do that :

$ pidof -o pid program_name

To print the PIDs of the processes that are running with the same root directory

To return the PIDs of the processes that are running with the same root directory, you can use the -c option to do that :

$ sudo pidof -c pid program_name

The above option only can be used when pidof command is run as root or sudo user.


To find process id of a program and kill it

You can use the pidof command with the kill command to kill or terminate a program.

For example, if the Firefox browser is become unresponsive, and you need to kill the Firefox processes, then first find the PIDs of Firefox processes with pidof command:

$ pidof firefox

When you run the above command, it will display PIDs of all Firefox processes.

After found process IDs , send the SEGTERM signal to terminate all of them:

$ sudo kill -9 5125 2504 3564 1856 1971

You can also terminate the programs in one command:

$ sudo kill -9 $(pidof firefox)

That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top