Post a Comment
I doubt Linus reads OSNews. Alan might.
Actually, here is what I've done:
=========================================
#!/bin/bash
RSS_LIMIT=393216
while true
do
LINE=`ps ax -o euser=,pid=,rss=,command= --sort -rss | grep -v "^root" | head -1l`
MEM=`echo $LINE | awk '{print $3}'`
PROC=`echo $LINE | awk '{print $2}'`
if [ $MEM -gt $RSS_LIMIT ]
then
date
echo "Killing with 15: $LINE"
kill -15 $PROC
sleep 5
echo "Killing with 9: $LINE"
kill -9 $PROC
echo "=========================="
echo "$LINE" | mail -s "limit_mem.sh kill notice" my@emailaddr.com
fi
sleep 5
done
=========================================
This gives me an easy way of controlling things and monitoring when a process gets zapped. It is actually better than ulimit, which simply denied the request for memory and I never find out about it. My goal, here, is to limit all nonroot processes to < 384MB of RSS. If any process is using more, I want it zapped, and I want to know about it. I might need to up the limit later, but 384MB seems a good starting point.
The down side to this is processor usage. This machine runs 60 desktops in addition to some other stuff and it is not uncommon for it to top 4000 processes. Thus processor usage for my script runs about 5%. Considering that this is a dual processor Intel(R) Xeon(TM) CPU 3.20GHz, that's not too bad. It works out to 2.5% of overall processor, and maybe 2.2% if you take into account hyperthreading. I could increase the sleep duration, but I *do* want it to act quickly when it is needed.
However, it would still be *really* nice to have functional -v and -d limits in Linux!





0