Chinaunix首页 | 论坛 | 博客
  • 博客访问: 527788
  • 博文数量: 96
  • 博客积分: 2960
  • 博客等级: 少校
  • 技术积分: 1850
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-11 15:25
文章分类

全部博文(96)

文章存档

2009年(37)

2008年(59)

我的朋友

分类: LINUX

2009-01-15 14:59:22

#!/bin/sh
#GetmemUsageModified2

USAGE="Usage: $0 processName"

if [ $# -ne 1 ]; then
   echo $USAGE
   exit 1
fi

# In case the monitored process has not yet started
# keep searching until its PID is found
PROCESS_PID=""
while :
do
   PROCESS_PID=`/sbin/pidof $1`

   if [ "$PROCESS_PID.X" != ".X" ]; then
      break
   fi
done

LOG_FILE="memusage.csv"

echo "ElapsedTime,VmSize,VmRSS" > $LOG_FILE

ELAPSED_TIME=`date`
PERIOD=2        # seconds

while :
do
 if [ -d /proc/$PROCESS_PID ] ; then
   VM_SIZE=`awk '/VmSize/ {print $2}' < /proc/$PROCESS_PID/status`
   if [ "$VM_SIZE.X" = ".X" ]; then
      continue
   fi
   VM_RSS=`awk '/VmRSS/ {print $2}' < /proc/$PROCESS_PID/status`
   if [ "$VM_RSS.X" = ".X" ]; then
      continue
   fi
   echo "$ELAPSED_TIME,$VM_SIZE,$VM_RSS" >> $LOG_FILE
   sleep $PERIOD
   VM_SIZE=""
   VM_RSS=""
   ELAPSED_TIME=`date +%H:%M:%S:%N`
 else
 echo "$1 is no longer a running process"
 exit 0
 fi
done

阅读(1237) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~