I have a single core VPS with a load average that goes beyond 25 at times. When it reaches that, it becomes unbearably slow, and even commands run through dash
, which is faster and uses less RAM than bash
, takes a while to run. How can I track down what process is causing the high load?
You can install
htop
. Good thing abouthtop
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
:Start it:
Press
F6
to sort the processes, then using the navigation key you can choosePERCENT_CPU
and press enter.Or you can use
top
in this way (source):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
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
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
:Get the three processes with the most higher CPU usage, using
top
:Get the three processes with the most higher CPU usage, using
ps aux
: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:
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.
Use
top
commandsource
good youtube tutorial