Finding the Process ID (PID) on Linux
Every program running on your system is assigned a number that uniquely
identifies it. This is known as the Process ID (commonly referred to as
PID). Proctal needs this number to identify the program you want to
take control of.
These are a couple of methods for finding the PID of a program on Linux.
pidof takes the name of the program as its first argument and prints a list of PIDs of all matching programs, separated by spaces.
$ pidof program-name 12345
pgrep takes an Extended Regular Expression and prints a list of PIDs of all programs whose name or command line match the expression.
$ pgrep prog*am-n?me 12345 12346
ps and grep
grep matches patterns and ps prints a row for each program running on the system. By piping the output of ps to grep, you can find the row for the program you are interested in.
$ ps ax | grep program-name 12345 pts/0 S+ 0:00 program-name argument1 argument2
The first column is the PID and the last column is the command line.
Due to a race condition, the grep command matches itself sometimes.