[OT] keep memory under control

Roberto A. Foglietta roberto.foglietta at gmail.com
Fri Aug 31 15:02:13 UTC 2007


Hi to all folks,

 sorry for the OT but I hope these scripts will be usefull for you too

 If I would keep trace of memory (in order to find some naqsty memory
leaks) amount used this script for bb-ash would work in your opinion?


getrssmem() {
local rss=0 lst="$(ls -1 /proc/*/statm | grep -v $$)"
local val="$(for i in $lst; do cat $i 2>/dev/null | cut -d\  -f2; done)"
for i in $val; do let rss+=$i; done
echo $rss
}

getkrnmem() {
local str x y z krn
str=$(free | head -n2 | tail -n1)
x=$(echo $str | cut -d\  -f3)
y=$(echo $str | cut -d\  -f5)
z=$(echo $str | cut -d\  -f6)
let krn=$x-$y-$z-$1
echo $krn
}

waituntilminute() {
local x
let x=$(date +%s)%60
let x=60-$x
sleep $x
}

while true; do
waituntilminute
rss=$(getrssmem); echo -n "$rss "; getkrnmem $rss
done

 Cheers,
-- 
/roberto



More information about the busybox mailing list