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

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

In this tutorial I will show you, 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.

Here, 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
4659
[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
4659

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

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!
 
Enjoyed this video?
How to grab process IDs (PIDs) in Linux / Unix
"No Thanks. Please Close This Box!"