How do I find the process with the highest load?
You can install htop
. Good thing about htop
is that it will show you your usage per CPU, as well as a meaningful text graph of your memory and swap usage right at the top.
To install htop
:
sudo apt-get install htop
Start it:
htop
Press F6
to sort the processes, then using the navigation key you can choose PERCENT_CPU
and press enter.
Or you can use top
in this way (source):
top -b -n 1 | head -n 12
The below is merely stolen from Unix.SE: Find the process which is taking maximum CPU usage if CPU usage is more than 60%?, though of course adapted to this question.
list processes by specific CPU usage
ps ahux --sort=-c | awk '{if($3>0.0)printf"%s %6d %s\n",$3,$2,$11}'
This gives a list of the processes which have a CPU usage >0.0
%, you can change this value according to your needs, e.g. >50.0
. Each line contains the CPU usage in percent, the PID and the file of the process.
list processes with the most CPU usage
ps ahux --sort=-c | awk 'NR<=5{printf"%s %6d %s\n",$3,$2,$11}'
This shows the top 5 (NR<=5
) processes currently causing the most CPU load.
Yesterday I was studying awk
and I played with the other two answers. Here is the result:
Get only the the process with the most higher CPU usage, using
ps aux
:ps auxh | awk -v max=0 '{if($3>max){CPU=$3; PID=$2; NAME=$11; max=$3}} END{printf "%5s %6d %s\n",CPU,PID,NAME}'
Get the three processes with the most higher CPU usage, using
top
:top -b -n 1 | awk 'NR>7 && NR<11 {printf "top: %5s %6d %s %s\n",$9,$1,$12,$13}'
Get the three processes with the most higher CPU usage, using
ps aux
:ps auxh --sort=-c | awk 'NR<=3 {printf "ps: %5s %6d %s\n",$3,$2,$11}'
I've tried to run the last two commands simultaneously (with <command>; wait; <command>
and <command> & <command> &
), but then I've realised it is not possible at all :)
References:
- The other two nice answers from the current question (and this comment of @αғsнιη).
- Find the max value of column 1 and print respective record from column 2 from file.
- How to run awk for some number of lines?