Finding a running process (pid) by name in Linux



Written by Jordon Mears on November 13, 2006

 

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.

look at some more Print Add to Favorites RSS Feeds