How to grab process IDs (PIDs) in Linux / Unix

An user can send signals to processes by using the process ID (PID) or the process name.

In this article I will show you how to grab the PIDs with pgrep and pidof.

How to get a process ID (PID) with pgrep:

Syntax: pgrep process_name

$ pgrep vim
[1]+ Stopped vim

You need to kill a process by its PID when you have, for example 3 instances of that process running and need to close only one, or two.

How to get a process ID (PID) with pidof:

Syntax: pidof process_name

$ pidof vim

If you have more than one instance of a program running, pidof and pgrep will show you all the PIDs of the process.

$ ps | grep vim
4672 pts/2 00:00:00 vim
4673 pts/2 00:00:00 vim
4674 pts/2 00:00:00 vim

$ pidof vim
4674 4673 4672

Tagged with: , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!