So you have a process running that took control of your system resources. hmm.. lets kill that process..
Generally a process loose its way because of loose pointers or a dependent resource is not responding or there can be any number of other reasons. I would generally shutdown the non responding process and start it again so that your system performance do no suffer.
Linux comes with commands like kill, killall to kill the processes. I will recommend not using killall for a start.
First up is that we would like to know which processes are running in our system, for that we will use ps command as shown below. Read more about this command here http://unixhelp.ed.ac.uk/CGI/man-cgi?ps
This will list all the processes running on our system. but say the troubled process is a php script that is stuck in its for loop. I will thus pipe the output of ps command to grep command to find the process ID of this phpscript
- [root@jaspreet ~]# ps aux
- [root@jaspreet ~]# ps aux | grep php
The above command will produce an output shown below (example)
- root 14540 0.0 1.2 21912 6304 ? Ss 20:00 0:00 php -q /var/www/reps/contacthouse.php
- root 14607 0.0 0.1 4120 676 pts/0 R+ 22:36 0:00 grep php
We can also utilize a command called pidof as shown below
- [root@jaspreet ~]# pidof php
The problem with above command is that we can not pin point which php script we need to kill. but for killing processes such as httpd, mysql etc its ok to rely on the output of the above command.
now that we got hold of the process that we need to kill that is 14540 we run the command below to kill it.
- [root@jaspreet ~]# kill 14540
Read more about kill command here http://unixhelp.ed.ac.uk/CGI/man-cgi?kill
The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.
as per the command definition above you may need to use -9 switch to force kill the process as shown below
- [root@jaspreet ~]# kill -9 14540
killall on the other hand kills processes by their name, so to kill a process called httpd we will run the command below
- [root@jaspreet ~]# killall -9 httpd
If you would like to read more about killall please do so by browsing to URL http://unixhelp.ed.ac.uk/CGI/man-cgi?killall
I hope this helps