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