Linux内存泄漏检测shell脚本
程序员文章站
2022-06-29 23:29:38
本文实例为大家分享了linux内存泄漏检测的shell脚本,供大家参考,具体内容如下
#!/bin/sh
if [ $# -ne 1 ]; then...
本文实例为大家分享了linux内存泄漏检测的shell脚本,供大家参考,具体内容如下
#!/bin/sh if [ $# -ne 1 ]; then echo "usage: `basename $0` process_name" exit 1 fi appname=$1 proc="`ps -ef | grep "$appname" | grep -v "grep" | grep -v "awk" | grep -v $0 | awk '{print $1}'`" if [ -z $proc ]; then echo "invalid process_name" exit 1 fi smaps="/proc/$proc/smaps" status="/proc/$proc/status" echo "proc ---$proc----" oldheap="0" while : do #heap="`cat $status | grep "vmdata" | awk '{print $2}'`" heap=`cat $smaps | grep -a 5 "heap" | grep "rss" | awk '{print $2}'` if [ $heap -lt $oldheap ]; then echo "`date` heap -`expr $oldheap - $heap` to $heap kb" oldheap=$heap elif [ $heap -gt $oldheap ]; then echo "`date` heap +`expr $heap - $oldheap` to $heap kb" oldheap=$heap fi sleep 1 done
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇: 怎么瘦腿和屁股