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

enter image description here

Press F6 to sort the processes, then using the navigation key you can choose PERCENT_CPU and press enter.

enter image description here

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?

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

ps -Flww -p %PID

just use the PIDs from the output of the first command and place it on the "%PID" place. Just using the man page:

To see every process with a user-defined format: ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm ps -Ao pid,tt,user,fname,tmout,f,wchan -l -l - Long format. The -y option is often useful with this. -F Extra full format. See the -f option, which -F implies. w Wide output. Use this option twice for unlimited width.

-p pidlist Select by PID. This selects the processes whose process ID numbers appear in pidlist. Identical to p and --pid.