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
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
Leave a Reply