#!/bin/sh
mem=`free -m |
linuxjishu/13830.html target=_blank class=infotextkey>awk 'NR==2{print $2}'`
ps -aux 2>&1 | sort -k 4 -r | awk '$4 ~ /^[0-9]/ && $4>0 {print $4,$11}' | awk '{print $1/100*mem" "$2}' mem=$mem | sort -k 2 | awk '
{
a[$2] += $1;
b[$2]++;
total += $1;
total++;
}
END{
for(i in a){
t=i;
gsub(/:|.*//, "", t);
printf "%10s %sn" ,a[i]"MB", t"["b[i]"]";
}
print "Memory Total: "mem"MB, u
sed: "total"MB, free: "mem-total"MB."
}' mem=$mem | sort -n -r
[root@Test230 zy]# sh mem.sh
3024.17MB java[17]
78.96MB java[1]
3.948MB
python[1]
3.948MB ntpd[1]
3.948MB iscsid[1]
3.948MB gdmgreeter[1]
Memory Total: 3948MB, used: 3140.92MB, free: 807.08MB.