pidof Command in Linux: Find Process IDs by Name

pidof 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 the Linux pidof command.
How to Use the pidof Command
There are different implementations of pidof for Red Hat and Debian based distributions. On Red Hat distributions, the pidof command is a part of the procps-ng package, while on Debian, it is part of sysvinit-utils. We will go over the options that are common to both implementations.
The syntax for the pidof command is as follows:
pidof [OPTIONS] PROGRAM_NAMEThe command accepts zero or more names as arguments, but typically, you would pass only one name to pidof.
When invoked without any option, pidof will print the PIDs of all running programs that match with the given name. For example, to find the PID of the SSH server, you would run:
pidof sshdIf there are running processes with names matching sshd, their PIDs will be displayed on the screen. If no matches are found, the output will be empty.
4382 4368 811pidof returns 0 when at least one running program matches with the requested name. Otherwise, the exit code
is 1. This can be useful when writing shell scripts.
To be sure that only the PIDs of the program you are searching for are displayed, use the full pathname to the program as an argument. For example, if you have two running programs with the same name located in two different directories pidof will show PIDs of both running programs.
By default, all PIDs of the matching running programs are displayed. Use the -s option to force pidof to display only one PID:
pidof -s program_nameThe -o option allows you to exclude a process with a given PID from the command output:
pidof -o pid program_nameWhen pidof is invoked with the -o option, you can use a special PID named %PPID that represents the calling shell or shell script.
To return only the PIDs of processes running with the same root directory, use the -c option. This option is ignored for non-root users, since they cannot check the root directory of processes they do not own. Run it as root or with sudo
:
sudo pidof -c program_nameExample Usage of the pidof Command
The following example shows how to use the pidof command in combination with the kill
command to terminate a program.
Suppose the Firefox browser has become unresponsive, and you need to kill the Firefox processes. First, find the PIDs, with pidof:
pidof firefoxThe command will print all Firefox processes:
2551 2514 1963 1856 1771Once you know the Firefox PIDs, send them the default SIGTERM signal to ask the processes to exit gracefully:
sudo kill 2551 2514 1963 1856 1771You can also use command substitution $(...) to find and terminate the program in a single command:
sudo kill $(pidof firefox)If a process ignores SIGTERM and refuses to exit, send the stronger SIGKILL signal with kill -9 to force it to stop:
sudo kill -9 $(pidof firefox)If you would rather match and signal processes by name in one step, the pkill
and pgrep
commands cover that workflow.
Quick Reference
Both implementations support these commonly used options:
-s- Single shot. Return only one PID.-c- Return only PIDs that share the same root directory (root orsudoonly).-o pid- Omit the given PID from the output. The special value%PPIDmatches the calling shell or script.-x- Also match shells running a script with the given name.-q- Quiet. Print nothing and only set the exit status.
The sysvinit implementation used by Debian and its derivatives also supports:
-z- Also detect processes stuck in zombie (Z) state.-n- Skipstat()calls on binaries that live on network filesystems such as NFS.-d sep- Usesepas the output separator instead of a space.
The procps-ng implementation used by Fedora, RHEL, and related distributions also supports:
-w- Include processes without a visible command line, such as kernel worker threads.-t- Return thread IDs instead of process IDs.-S sep- Usesepas the output separator.
Run man pidof to confirm which options your installed implementation provides.
Conclusion
The pidof command gives you a quick way to look up the PID of a running program by name, which is useful when you need to signal, monitor, or script around a specific process. Pair it with kill to stop a misbehaving program, or use the -s option when you only need a single PID.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page