Skip to content

pidof

Prints the PIDs of a running program, found by its exact program name.

pidof output

Syntax

pidof [OPTION]... PROGRAM...

Options

Option Description
-s Only print one PID
-x Also find scripts by their name
-o PID Ignore this PID

Examples

Find all PIDs of a program:

pidof nginx
814 813 812

All PIDs are printed in one line, separated by spaces.

Get only one PID:

pidof -s nginx
814

Find the main SSH server process:

pidof sshd
640

A program that is not running:

pidof redis-server
echo $?
1

Find a running script:

pidof -x backup.sh
4410

When do I need it?

  • In scripts that need the PID of a program, for example to send it a signal
  • To check quickly whether a program is running (exit status 0 or 1)

pidof or pgrep?

pidof only looks for the exact program name and prints all PIDs in one line. pgrep can also search by user or command line and prints one PID per line.

The name must match exactly

pidof php-fpm finds nothing if the program is called php-fpm8.4. Check the exact name with ps -e or pgrep -l first.

pgrep · ps · lsof · kill