- 论坛徽章:
- 0
|
#!/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}' > $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
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/28158/showart_1798307.html |
|