#!/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.