Linux pidof Command Examples To Find PID of A Program/Command

pidof command

I am a new Linux system user and I using CentOS Linux on server. How can I find the process ID (PID) of a running program on Linux based system using shell prompt?

A PID is an acronym for process identification number on Linux or Unix-like systems. It is nothing but an identification number that is automatically assigned to each process when it is created.[donotprint]

pidof command details
DescriptionGet the process ID of a
running program
Root privilegesNo
Est. reading time5m
Table of contents

You can use pidof utility to find the process id’s (PIDs) by name. Please note that the pidof command only works on Linux based system, Unix user either try ps command or pgrep command to find the pid of a running program.


Find the process ID of a running program by name on Linux.


The basic syntax is as follows:

pidof command


pidof program


pidof [options] program1 program2 ... programN

NOTE: You may need to run this program as root user to find and kill pid of privileged programs.

pidof command examples

To find pid of lighttpd process, enter:
$ pidof lighttpd
Sample outputs:

Fig. 01: pidof command in action

Fig. 01: pidof command in action

Get only one pid of a program named php5-cgi

By default pidof displays all pids of named command/program:
$ pidof php5-cgi
Sample outputs (see fig.01):

2427 2426 2424 2423 2418 2387 2386 2385 2384 2383 2241 2240 2238 2237 2223

To display only one pid of the program pass the -s option as follows:
$ pidof -s php5-cgi
Sample outputs (see fig.01):


Get pids of scripts

The pidof command will not display pids of shell/perl/python scripts. To find the process id’s of shells running the named script called featch-data, pass the -x option:
$ pidof -x fetch-data

Omit processes

You can ask pidof commmand to ignore or omit processes with that process id. This is useful to ignore calling shell or shell script or specific pid. In this example, find all pids of lighttpd but omit pid # 4242:
# pidof -o 4242 lighttpd
You can use the special pid %PPID to name the parent process of the pidof program in shell scripts:

# please ignore our pid and get all pids of lighttpd on server
list=$(pidof -o %PPID lighttpd)
# .. now  do something on all pids stored in $list
for p in $list
  echo "Killing $p..."
  kill -TERM $p

Find pid of a program and kill it

In this example, find all PIDs of nginx server and kill it:

p=$(pidof nginx)
kill $p

Find pids of firefox and kill it focefully as the browser has stuck/frozen using kill command

p=$(pidof firefox)
kill -9 $p

pidof command options

From the pidof(8) command man page:

Option Description
 -s  Find only one pid i.e. single shot.
 -c  Only return process ids that are running with the same root directory. This option is ignored for non-root users, as they will be unable to check the current root directory of processes they do not own.
 -n  Avoid stat(2) system function call on all binaries which are located on network based file systems like NFS.
 -x  Find pid for scripts too.
 -o  Tells pidof to omit processes with that process id.
See also
  • pidof(8) Linux/Unix command man page

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum