java进程占用swap分区问题,导致swap分区快速增满不够用!!

 

for i in $( cd /proc;ls |grep "^[0-9]"|awk ' $0 >100') ;do awk '/Swap:/{a=a+$2}END{print '"$i"',a/1024"M"}' /proc/$i/smaps 2>/dev/null ; done | sort -k2nr | head -10

 

 写脚本swap_free.sh

#!/bin/bash
Free_swap=`free -h | awk '/Swap/{print $NF"M"}'`
Free_swap2=${Free_swap%%MM}
Max_size=$((200 * 1))
if [ ${Free_swap2} -le ${Max_size} ];then
kill -9 `ps -ef|grep java|grep -v grep|awk '{print $2}'`
fi

 

 

 

 从下面可以看出,swap分区恢复正常!!

 

posted @ 2022-09-18 17:47  往事已成昨天  阅读(367)  评论(0编辑  收藏  举报