亲宝软件园·资讯

展开

Linux内存泄漏检测 Linux内存泄漏检测shell脚本

STARTRACK 人气:0
想了解Linux内存泄漏检测shell脚本的相关内容吗,STARTRACK在本文为您仔细讲解Linux内存泄漏检测的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Linux,内存泄漏,下面大家一起来学习吧。

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

加载全部内容

相关教程
猜你喜欢
用户评论