OOM watcher
做了个梦,梦到组里所有的服务器都被我的程序out of memory了。。。
The script
#!/bin/sh
if [ $# -ne 2 ];
then
echo "Invalid number of arguments"
exit 0
fi
while true;
do
SIZE=$(pmap $1|grep total|grep -o "[0-9]*")
SIZE=${SIZE%%K*}
SIZEMB=$((SIZE/1024))
echo "Process id =$1 Size = $SIZEMB MB"
if [ $SIZEMB -gt $2 ]; then
printf "SIZE has exceeded.\nKilling the process......"
kill -9 "$1"
echo "Killed the process"
exit 0
else
echo "SIZE has not yet exceeding"
fi
sleep 10
done
Please refer to
https://askubuntu.com/questions/54747/automatically-kill-a-process-if-it-exceeds-a-given-amount-of-ram
评论已关闭