pidof command is used to find the process ID (PID) number of the process with the specified name. This is useful for identifying and managing processes running on a Linux system.
The basic syntax of the
pidof command is as follows:
pidof [OPTIONS] name
name is the name of the process for which the PID is to be found.
For example, to find the PID of the
apache2 process, run the following command:
The output would be a list of PIDs separated by spaces, like this:
1234 5678 9012
This means that there are three instances of the
apache2 process running, with PIDs 1234, 5678, and 9012.
pidof command can also be used in scripts to perform various actions on processes. For example, the following command kills all instances of the
kill $(pidof apache2)
This command uses command substitution to pass the output of
pidof to the
kill command, which sends a SIGTERM signal to each process.
The following table lists the available options for the
|-c||Only display the number of PIDs found|
|-x||Only match processes with the exact name specified|
|-s||Only match processes in the same session as the PID of the calling process|
|-o||Only match processes with the same effective user ID as the PID of the calling process|
|-n||Only match processes with the same name as the PID of the calling process|
pidofreturns no output, it means that the specified process is not running.
pidofreturns multiple PIDs, it means that there are multiple instances of the specified process running.
pidofreturns an error message, check that the process name is spelled correctly and that the process is running.
pidofcommand is a simple and useful tool for managing processes on a Linux system.
- The command can be used in scripts and other automation tools to perform various actions on processes.
pidofcommand is typically installed by default on most Linux distributions.