统计使用内存和CPU前10进程


memory () {
  temp_file=`mktemp memory.XXX`
  top -b -n 1 > $temp_file
  
  tail -n +8 $temp_file | awk '{array[$NF]+=$6}END{for (i in array) print array[i],i}' | sort -k 1 -n -r | head -10
  
  rm -f $temp_file
}



cpu () {
  temp_file=`mktemp memory.XXX`
  top -b -n 1 > $temp_file
  
  tail -n +8 $temp_file | awk '{array[$NF]+=$9}END{for (i in array) print array[i],i}' | sort -k 1 -n -r | head -10
  
  rm -f $temp_file
}
echo "memory"
memory
echo "cpu"
cpu

原文地址:https://www.cnblogs.com/persisit/p/13691422.html