统计使用内存和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

posted @ 2020-09-18 15:17  pigeast  阅读(137)  评论(0编辑  收藏  举报