I need to print the 10 processes that are using the most CPU. Also I need to print their ID, and the command they were started with.
What I've found is that the command ps -ax -u
prints all the processes and their %CPU usage. The command ps -ax -u --sort pcpu
prints all the processes sorted by the %CPU usage, from the least to the most, but I need to print only 10 processes from the most to the least. I have to use something like sort -r
to make a reverse sorting, but the command ps -ax -u --sort -r pcpu
produces an error.
So, how can I make a reverse sorting and print only 10 of the processes?