• Home
  • About Me
  • Welcome to Short Linux hints
Short hints about Linux


  • Tags

    hacking Linux linux cpanel courier maildir mailbox exim security viruses worms
  • Blogroll

    • Geany
    • Handy one-liners for sed
    • Linux By Example
    • Penguin Tutor

May 04

Manage heavy Linux processes during high CPU load

Linux Add comments

Here come the next short bash scripts which show the simplicity and power of Bash / Linux. In order to manage heavy Linux processes during high CPU load we will do 2 things:

1. Try to re-nice the heavy processes each 2 mins. Sometimes this might help and allow an important process to complete while saving the system from overloading. For this purpose we set a cron to run each 2 mins:

*/2 * * * * test `cat /proc/loadavg |cut -d '.' -f1` -gt 5 && renice 19 `ps aux | sort -rn +2 2>/dev/null | head -1 | awk '{print $2}'`

In plain words this script means: Check if the average unix CPU load is higher than 5. If it is, renice to value 19 (the lowest priority a process can have) the most CPU consuming process.

2. Very often only renicing a process might not work and the system will continue to overload. For this purpose we will set the next cron to run each 10 mins:

*/10 * * * * test `cat /proc/loadavg |cut -d '.' -f1` -gt 15 && kill -9 `ps aux | sort -rn +2 2>/dev/null | head -1 | awk '{print $2}'`

This command will kill immedatialy the heaviest process when the system load is higher than 15. This could be a life saver.

Comments are closed.

Powered by WordPress .::. Designed by SiteGround Web Hosting

cssandhtml