Reputation: 377
I would like to have the cpu percentage in decending order. When I give the command :
top -bn 1 | grep "^ " | awk '{ printf("%-8s %-8s \n", $2, $9); }' | head -8
It shows processes which are not the top most using CPU.
Upvotes: 8
Views: 40606
Reputation: 356
In your command, you have
grep "^ "
which filters out lines that do not start with a space.
With this, you're filtering out processes that have PIDs longer than 4 characters, since the top
command left pads the PIDs to 5 characters.
Use grep "^[0-9 ]"
instead.
Upvotes: 1
Reputation: 2998
Run top as a process (I'm using Ubuntu 14.04)
top
Once in top...
P <- Sort by CPU usage
M <- Sort by MEM usage
z <- Add cool visual colors
x <- Highlight column you are currently sorting by
Upvotes: 37