Killing a process on Linux systems
Have you ever had a stray process eating up all your system resources or just wanted to terminate a program? This HowTo will guide you through the steps of killing any process on your Linux system.
Step 1
With escalated privileges type ps aux | less in your terminal window.
ps aux | less
This will display a list of all processes currently running, along with their process ID (PID), process status (STAT), command names and various statistics. Read this HowTo for more about viewing running processes on a Linux system.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 1992 708 ? Ss Jan01 0:00 init [2] root 2 0.0 0.0 0 0 ? S Jan01 0:00 [migration/0] root 3 0.0 0.0 0 0 ? SN Jan01 0:00 [ksoftirqd/0] root 4 0.0 0.0 0 0 ? S Jan01 0:00 [watchdog/0] root 5 0.0 0.0 0 0 ? S< Jan01 0:00 [events/0] root 6 0.0 0.0 0 0 ? S< Jan01 0:00 [khelper] root 9 0.0 0.0 0 0 ? S< Jan01 0:00 [xenwatch] root 10 0.0 0.0 0 0 ? S< Jan01 0:00 [xenbus] daemon 1506 0.0 0.0 1924 436 ? Ss Jan01 0:00 /usr/sbin/atd root 1526 0.0 0.1 2044 888 ? Ss Jan01 0:00 /usr/sbin/cron user 9381 16.5 15.0 700080 389304 ? Sl Jan01 489:30 /usr/lib/firefox-x.x/firefox www 28284 0.6 4.5 70036 23972 ? R 09:51 0:09 /usr/sbin/apache2 -k start www 28402 0.7 3.9 69620 20944 ? S 09:59 0:07 /usr/sbin/apache2 -k start user 28435 0.7 3.9 69600 20732 ? S 10:06 0:04 /home/user/linuxlookup.pl
Step 2
From the output generated, you need to identify the PID of the process you want to stop. For example, to stop Firefox you would look up the process identification number (PID) in the output and issue the following command:
kill -9 9381
Also, a method of killing all process by name without having to lookup the PID is with:
killall -9 firefox
The processes shown by ps can be narrowed down to a specific program or those belonging to a user by piping the output through grep. For example, processes belonging to a user with a username 'linuxlookup' can be displayed with ps -ef linuxlookup.