今天写了一个Linux程序,用到了多个双向链表,估计由于释放问题导致内存占用过高,在网上找到比较好用的一个脚本,可以比较详细的统计Linux内存使用情况,现转载如下:
转帖: http://dreamsky.com.tw/phpbb/post146446.html?sid=8f65dacbea666651027003d540f00dee
#!/bin/sh
#$Id: memuse.sh, v0.1 2008/4/21 Akira Exp $
#View Memory Use Status
echo ""
vmstat -s -S M
echo ""
PS=`ls /proc/*[0-9]*|grep :` ;
PSList=`echo $PS | tr -d '/proc' | tr -d ':' | sort `;
echo -e "#PID\t\t#MEMSize\t\t#MEMUse\t\t\t#Name\t\t#CMD"
for PID in $PSList
do
test -e /proc/$PID/status && \
sPID=`cat /proc/$PID/status | grep ^Pid:` && \
sMEMsize=`cat /proc/$PID/status | grep ^VmSize: | awk '{print $1,$2/1024,"M"}'` && \
sMEMuse=`cat /proc/$PID/status | grep ^VmRSS: | awk '{print $1,$2/1024,"M"}'` && \
sName=`cat /proc/$PID/status | grep ^Name:` && \
if [ -e /proc/$PID/exe ]
then
sCMD=`ls -alF /proc/$PID/exe | awk '{print }' | tr -d '$*' | awk '{print $11}'`
fi
echo -e "$sPID\t$sMEMsize\t$sMEMuse\t$sName\tCMD:\t$sCMD" | egrep 'VmSize|VmRSS' >> /tmp/mem001
done
cat /tmp/mem001 | sort -n -r -t " " -k 2 | head -10
rm -rf /tmp/mem001
#$Id: memuse.sh, v0.1 2008/4/21 Akira Exp $
#View Memory Use Status
echo ""
vmstat -s -S M
echo ""
PS=`ls /proc/*[0-9]*|grep :` ;
PSList=`echo $PS | tr -d '/proc' | tr -d ':' | sort `;
echo -e "#PID\t\t#MEMSize\t\t#MEMUse\t\t\t#Name\t\t#CMD"
for PID in $PSList
do
test -e /proc/$PID/status && \
sPID=`cat /proc/$PID/status | grep ^Pid:` && \
sMEMsize=`cat /proc/$PID/status | grep ^VmSize: | awk '{print $1,$2/1024,"M"}'` && \
sMEMuse=`cat /proc/$PID/status | grep ^VmRSS: | awk '{print $1,$2/1024,"M"}'` && \
sName=`cat /proc/$PID/status | grep ^Name:` && \
if [ -e /proc/$PID/exe ]
then
sCMD=`ls -alF /proc/$PID/exe | awk '{print }' | tr -d '$*' | awk '{print $11}'`
fi
echo -e "$sPID\t$sMEMsize\t$sMEMuse\t$sName\tCMD:\t$sCMD" | egrep 'VmSize|VmRSS' >> /tmp/mem001
done
cat /tmp/mem001 | sort -n -r -t " " -k 2 | head -10
rm -rf /tmp/mem001
转帖: http://dreamsky.com.tw/phpbb/post146446.html?sid=8f65dacbea666651027003d540f00dee