Monday, November 25, 2019

How to stop or kill a process running on your Linux Server


To find out the processes running on your server :
ps aux
This will show you the ‘PID’ of the process along with it’s other information. You can delete a process by using the ‘kill’ command with the process PID
kill 16516
Sometimes you run into errors that require emergent steps like killing of certain process. For example, if you have certain PHP processes running in the background which are stuck and taking up valuable server resources, you can kill the PHP processes only on the server instead of restarting the whole server.
To list all the processes of a certain name :
ps aux | grep 'process_name'
For example if you wish to display all the PHP processes :
ps aux | grep 'php'
You can further improve this command,
ps aux | grep '[p]hp'
To kill all the processes of a given name, for example all MYSQL processes :
kill $(ps aux | grep '[m]ysql' | awk '{print $2}')
Just replace the mysql with the process name you wish to kill all processes of and also don’t forget to add the first character in ‘[ ]’ brackets.
Load disqus comments

0 comments