精确计算rss使用值
在 也看linux内存去哪儿了 篇,最后提到精确计算rss内存的方法,这里写了一个简单的脚本,通过pmap遍历每个进程。将所有结果遍历汇总到一个文件后,再将使用相同的l内存地址的去重,完了再求和。脚本如下:
1# cat rrs.sh
2#!/bin/bash
3filename=`cat /proc/sys/kernel/random/uuid`
4for PROC in `ls /proc/|grep "^[0-9]"`
5do
6pmap -xq $PROC|grep -v $PROC: >> /tmp/$filename
7done
8RRSvalue=`awk '{print $1,$3}' /tmp/$filename|awk '!a[$0]++'|awk 'BEGIN{sum=0}{sum+=$2}END{print sum}'`
9echo $RRSvalue"kB"
10rm -rf /tmp/$filename
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/linux-rrs-res/4049.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.