[plain] view plaincopy
  1. #!/bin/sh  
  2. mem=`free -m | awk 'NR==2{print $2}'`  
  3. 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 '  
  4. {  
  5.    a[$2] += $1;  
  6.    b[$2]++;  
  7.    total += $1;  
  8.    total++;  
  9. }  
  10. END{  
  11.   for(i in a){  
  12.     t=i;  
  13.     gsub(/:|.*\//, "", t);  
  14.     printf "%10s   %s\n" ,a[i]"MB", t"["b[i]"]";  
  15.   }  
  16. print "Memory Total: "mem"MB, used: "total"MB, free: "mem-total"MB."  
  17. }' mem=$mem | sort -n -r  

执行结果:

 

[plain] view plaincopy
  1. [root@Test230 zy]# sh mem.sh   
  2.  3024.17MB   java[17]  
  3.    78.96MB   java[1]  
  4.    3.948MB   python[1]  
  5.    3.948MB   ntpd[1]  
  6.    3.948MB   iscsid[1]  
  7.    3.948MB   gdmgreeter[1]  
  8. Memory Total: 3948MB, used: 3140.92MB, free: 807.08MB.  

本文转自: http://blog.csdn.net/zhuying_linux/article/details/7480627

相关文章:

  • 2022-03-04
  • 2021-12-06
  • 2021-09-16
猜你喜欢
  • 2021-10-17
  • 2022-02-09
  • 2021-10-05
相关资源
相似解决方案