Killing Memory Hogs

On an old server I temporarily added the following script as a cron job to find and kill processes using too much memory. This is just a stop gap until we get to the root of the problem.

#!/bin/bash
for i in `ps -efl | grep “httpd” | awk ‘{ if ($10 > 16000) {print $4″ ” } }’`
do
`kill -9 $i`
done

So the script checks for httpd processes using more than about 124Mb and kills them. $4 refers to the Process ID in ps -efl and $10 the memory usage.
I added this to the crontab with the following:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/webprogs/kill_memory_hogs.sh > /dev/null

Unfortunately I could not use the short notation on this older OS:

*/5 * * * * /usr/local/webprogs/kill_memory_hogs.sh > /dev/null

Obviously this could be fairly dodgy if there are any httpd processes which legitimately need a lot of memory so I will wait for the phone calls.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>