Sometimes you may find your server in a state of high load caused by out control of processes. First you’ll want to use a command like htop, top, or ps, to get an idea on the server’s current state.
After you have an initial assessment of the server’s current load you will have a better idea on how to proceed. More often than not the load is likely being caused by regular server traffic and usage.
Generally that will mean the load is being caused by a high number of Apache, PHP, or MySQL processes. After all most servers are hosting websites and these are the most commonly required programs to run a website. With that in mind during times of high load it’s often nice to quickly stop all processes of a certain type.
Using killall to reduce load on a web server
In this article we assume that our server is experiencing load issue is caused by a high volume of website traffic. This means our initial check will likely show a large number of Apache and PHP processes running.
For our example most of the processes on the server are Apache (shown below); make note that the Apache processes are actually called httpd.
Above you can see that the majority of the items listed are all `httpd -k start`; this indicates they are Apache web server processes. If you’re familiar with htop you will also notice that the server’s current load is at 11.89 and that it’s only a 2 core server with 1GB of RAM. With all that in mind the current load is considered pretty high.
Since we already know that the majority of the load is likely coming from Apache we can use the killall command to address the issue. With this useful command you will be able to quickly stop a process on a server. To stop the Apache processes we will run the following command:
killall httpd
If you attempt running the command multiple times you will likely see the following output:
httpd: no process found
In this case this is a good sign, it means all the Apache processes have been stopped and are no longer running.
Since we used killall to stop Apache we will need to ensure we restart the Apache service before exiting the server. When you use killall to stop an out of control service (Apahce, PHP-FPM, MariaDB, etc) then you need to ensure you manually restart the service or your sites may not come back up. In our case we will run:
systemctl restart httpd