Pidof Command in Linux |
pidof is a command-line utility that permits you to discover the method ID of a operating program.
On this article, we’ll clarify how you can use the Linux
Learn how to Use the
pidof Command #
There are completely different implementations of
pidof for Purple Hat and Debian primarily based distributions. On Purple Hat distributions, the
pidof command is part of the
procps-ng package deal, whereas on Debian, it’s a part of
sysvinit-utils. We’ll go over the choices which are frequent for each implementations.
The syntax for the
pidof command is as follows:
pidof [OPTIONS] PROGRAM_NAME
The command accepts zero or extra names as arguments, however usually, you’d go just one identify to
When invoked with none possibility,
pidof will print the PIDs of all operating packages that match with the given identify. For instance, to search out the PID of the SSH server, you’d run:
If there are operating processes with names matching
sshd, their PIDs can be displayed on the display screen. If no matches are discovered, the output can be empty.
4382 4368 811
0 when not less than one operating program matches with the requested identify. In any other case, the exit code is
1. This may be helpful when utilized in shell scripts.
To make certain that solely the PIDs of this system you’re trying to find are displayed, use the total pathname to this system as an argument. For instance, in case you have two operating packages with the identical identify situated in two completely different directories
pidof will present PIDs of each operating packages.
By default, all PIDs of the matching operating packages are displayed. Use the
-s choice to pressure
pidof to show just one PID:
pidof -s program_name
-o possibility permits you to exclude a course of with a given PID from the command output:
pidof -o pid program_name
pidof is invoked with the
-o possibility, you should use a particular PID named
%PPID that represents the calling shell or shell script.
To return solely the PIDs of the processes which are operating with the identical root listing, use the
This feature works solely
pidof is run as root or
pidof -c pid program_name
Instance Utilization of the
pidof Command #
The next instance reveals how you can use the
pidof command together with the
kill command to terminate a program.
Let’s say the Firefox browser has grow to be unresponsive, and it is advisable to kill the Firefox processes. First, discover the PIDs, with
The command will print all Firefox processes:
2551 2514 1963 1856 1771
As soon as you understand the Firefox processes PIDs, ship the
SEGTERM sign to terminate all of them:
sudo kill -9 2551 2514 1963 1856 1771
You may as well use the command substitution expression
$(...), to terminate this system in a single command:
sudo kill -9 $(pidof firefox)
pidof command is used to search out out the PIDs of a selected operating program.
pidof is an easy command that doesn’t have quite a lot of choices. Sometimes you’ll invoke
pidof solely with the identify of this system you’re trying to find.
When you’ve got any questions or suggestions, be at liberty to go away a remark.