pidof: retrieve PID when searching for process names
Returns process ID (PID) searching for a process name.
Typical usage: automation, shell scripting, system adminstrationIntroduction 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 system | Package name | Installation |
---|---|---|
AlmaLinux | procps-ng |
|
Arch Linux | procps-ng |
|
Debian | sysvinit-utils |
|
Fedora | procps-ng |
|
openSUSE | sysvinit-tools |
|
Red Hat Enterprise Linux | procps-ng |
|
Rocky Linux | procps-ng |
|
Ubuntu | sysvinit-utils |
|
Your Linux distribution using a different package? Share your feedback.
Usage
Available options
Option | Description |
---|---|
-s | Only 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.
- How to find all process IDs by its process name
- How to see the cgroup of a process
- Swap memory information
- Hardening nginx with systemd security features
- How to see when a process was started
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:
Command | Category | Summary |
---|---|---|
basename | files | Strips directory and file name suffix from a given path |
chrt | processes | Sets Linux scheduler policy and priority for a process or command |
kill | processes | Sending signals to processes |
nice | processes | Runs commands with specified priority |
numactl | processes | Controls NUMA policy for processes and shared memory |
peekfd | processes | Tracks a process and show file descriptor activity |
pidstat | monitoring | Monitoring CPU, memory, and disk activity |
pidwait | processes | Wait for process to stop |
pmap | processes | Shows memory mapping of process |
prtstat | processes | Shows process details for selected process like state, CPU and memory usage |
pscap | capabilities | Display available capabilities for running processes |
pslog | logging | Shows which log files a process has opened |
pstree | processes | Show active processes and children like a tree |
pwdx | processes | Shows current working directory of a process |
renice | processes | Changes the priority of running processes |
slabtop | memory | Shows slab usage of kernel |
smem | memory | Show memory usage including swap |
strace | process inspection | Inspects running process |
units | data conversion | Converts a unit into another one, like from Celcius to Fahrenheit |
watch | processes | Monitors changes in output of specified command |