Pidof Command in Linux | - MS TV Life.COM

Pidof Command in Linux |

Pidof Command in Linux |

pidof is a command-line utility that permits you to discover the method ID of a operating program.

Pgrep Command in Linux |

On this article, we’ll clarify how you can use the Linux pidof command.

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:


The command accepts zero or extra names as arguments, however usually, you’d go just one identify to pidof.

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:

pidof sshd

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

pidof returns 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.

How to Install Mono on CentOS 8

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

The -o possibility permits you to exclude a course of with a given PID from the command output:

pidof -o pid program_name

When 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 -c possibility.

This feature works solely pidof is run as root or sudo consumer:

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.

How to Remove a Git Remote

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 pidof:

pidof firefox

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)

Conclusion #

The 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.

Pgrep Command in Linux |

When you’ve got any questions or suggestions, be at liberty to go away a remark.

Source link

Copy link
Powered by Social Snap