pidof: retrieve PID when searching for process names

Returns process ID (PID) searching for a process name.

Typical usage: automation, shell scripting, system adminstration

Introduction into pidof

The pidof command can return the process ID (PID) for a process similar to pgrep. It is a very useful tool to create one-liners where one command needs to take an action on a PID, but the you only have the name available.

Installation

When pidof is not installed by default, it can be added to the system using the relevant software package.

Package information for pidof

Operating systemPackage nameInstallation
AlmaLinuxprocps-ng
dnf install procps-ng
Arch Linuxprocps-ng
pacman -S procps-ng
Debiansysvinit-utils
apt install sysvinit-utils
Fedoraprocps-ng
dnf install procps-ng
openSUSEsysvinit-tools
zypper install sysvinit-tools
Red Hat Enterprise Linuxprocps-ng
dnf install procps-ng
Rocky Linuxprocps-ng
dnf install procps-ng
Ubuntusysvinit-utils
apt install sysvinit-utils

Your Linux distribution using a different package? Share your feedback.

Usage

Available options

OptionDescription
-sOnly return a single process ID (PID)

Missing an option in this overview? Share your feedback.

Examples using pidof

Check process IDs of nginx

pidof nginx

Example output:

# pidof nginx
554 553 552

Search for 'nginx' and for each process found, send default kill signal

kill $(pidof nginx)

Frequently Asked Questions

What is the pidof command and its purpose?

The pidof command returns the process ID (PID) of a process when searching for it by its name.

Which package provides the pidof command?

The command pidof is provided by the procps-ng, sysvinit-tools, or sysvinit-utils package.

Relevant articles using the pidof command

The following articles include an example on how to use pidof and might be worth further exploring.

Related and similar commands

Linux has a lot of tools and commands available and sometimes you just need that little other tool. Here is a list of commands that are similar or related to pidof:

Related and similar commands to pidof
CommandCategorySummary
basenamefilesStrips directory and file name suffix from a given path
chrtprocessesSets Linux scheduler policy and priority for a process or command
killprocessesSending signals to processes
niceprocessesRuns commands with specified priority
numactlprocessesControls NUMA policy for processes and shared memory
peekfdprocessesTracks a process and show file descriptor activity
pidstatmonitoringMonitoring CPU, memory, and disk activity
pidwaitprocessesWait for process to stop
pmapprocessesShows memory mapping of process
prtstatprocessesShows process details for selected process like state, CPU and memory usage
pscapcapabilitiesDisplay available capabilities for running processes
pslogloggingShows which log files a process has opened
pstreeprocessesShow active processes and children like a tree
pwdxprocessesShows current working directory of a process
reniceprocessesChanges the priority of running processes
slabtopmemoryShows slab usage of kernel
smemmemoryShow memory usage including swap
straceprocess inspectionInspects running process
unitsdata conversionConverts a unit into another one, like from Celcius to Fahrenheit
watchprocessesMonitors changes in output of specified command