Kill or Terminate a process in Linux

Sometimes we open so many tasks but these tasks are not shown as simple in taskmanger like Windows operating system but still we need to end that process or kill that process on our Linux machines either we are using GUI or CLI (using ssh or shell). It is quite simple and can be done in several ways in Linux.

First you can check all tasks running right now on your machine

$top

Output will be like that

top - 10:49:28 up 25 min,  2 users,  load average: 0.04, 0.60, 0.49
Tasks: 249 total,   2 running, 246 sleeping,   0 stopped,   1 zombie
Cpu(s): 11.6%us,  3.2%sy,  0.0%ni, 85.0%id,  0.0%wa,  0.2%hi,  0.0%si,  0.0%st
Mem:   2948232k total,  2089736k used,   858496k free,    46616k buffers
Swap:   524280k total,        0k used,   524280k free,   734452k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
 3885 techobia  20   0 1358m 476m  43m R  6.3 16.5   2:19.72 firefox            
 3357 techobia  20   0  390m  16m  11m S  5.0  0.6   0:03.43 gnome-panel        
 2600 techobia  20   0  539m 157m  44m S  3.7  5.5   1:21.30 skype              
 2004 apache    20   0  440m  30m  18m S  2.0  1.1   0:00.18 httpd              
 4113 techobia  20   0 1024m 174m  39m S  2.0  6.1   0:23.36 firefox            
 4277 techobia  20   0  345m  12m 9588 S  2.0  0.4   0:00.47 gnome-terminal     
 2024 root      20   0  226m  29m  15m S  1.3  1.0   0:31.36 Xorg    

Now as you want to stop or Kill firefox then you need to kill it like this

Safest way to kill the process is using SIGTERM (15) and at last without saving any data SIGKILL (9)

You can also check the PID of process by using this command too

#pidof firefox
or 
#ps aux | grep firefox

Output would be like that

#pidof firefox
4113

or
#ps aux | grep firefox
techobia  4113  5.8  6.7 1018848 199644 ?      Sl   10:45   0:40 /usr/lib64/firefox/firefox

Then to kill this process first try with safe method SIGTERM

## kill -SIGTERM PID
or 
## kill -15 PID

e.g. To close firefox

# kill -SIGTERM 4113

If it not works for you then use the unsafe method

# kill -SIGKILL 4113

You can also use killall command

# killall processname

e.g.

# killall firefox

OR

# killall -SIGKILL firefox

All the examples and results showm above were performed on Centos 6.5(64) Edition.