Finding a running process (pid) by name in Linux
I have always wondered how you find and kill frozen applications and run away programs in Linux, but to be honest I have never known of a good way to find the process id (either graphically or on the command line). So after a little searching I found the 'ps' (process status) command. It will give you a list of all of the processes running on a particular machine.
You need to use the 'a' option to see the processes by all users and the 'x' option to show all of the processes outside of the scope of the shell.
ps -ax
If you just run that command as is, the results will just scroll by. In order see and browse the results at you own pace you can pipe the list into 'less'.
ps -ax | less
Or if you want to search for a particular application process, instead of piping in 'less' you can pipe the results into grep.
ps -ax | grep search
For example I can find the process id of Firefox by doing something like this:
ps -ax | grep firefox 3399 ?? S 3:30.90 /Ap ... OS/firefox-bin -ps ... 3456 p1 S+ 0:00.00 grep firefox
This example output is from my MacBook. Now I can successfully kill the app by calling the kill command. In this example I can do this:
kill 3399
This also works on a Mac, but Mac's Force Quit features are pretty nice and there is really no need to use the command line.


December 27th, 2006 at 10:46:10
Since the writing of this article I have found that you can use regular expressions with the killall command (use -r option). However you must be careful to not accidentally kill more than you wanted to (use -i option to confirm each process before killing it).
December 28th, 2006 at 10:32:55
# ps -ax | grep firefox | awk ‘{print$1}’
This command will show the PID only of firefox.
as the requirement is to find PID only.