KK_3353
KK_3353

Reputation: 105

Calculate cpu through linux commands

I would like to know the cpu uage and i tried to get through the 'top' commands.

But seems used CPU above it shows "19 %" while in the process list it shows for 100% for cpu. So please let me know how to get the exact value for CPU usage.

top - 05:14:39 up 34 days, 14:57, 1 user, load average: 0.20, 0.31, 0.30 Tasks: 231 total, 2 running, 184 sleeping, 1 stopped, 1 zombie %Cpu(s): 19.0 us, 2.3 sy, 0.0 ni, 78.4 id, 0.1 wa, 0.0 hi, 0.2 si, 0.0 st KiB Mem : 16123248 total, 3329216 free, 7078736 used, 5715296 buff/cache KiB Swap: 1048572 total, 743164 free, 305408 used. 9380980 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 27928 root 20 0 415656 10196 5212 R 100.0 0.1 0:00.17 runc:[2:INIT] 27933 karthik+ 20 0 33992 3496 2956 R 6.2 0.0 0:00.01 top

enter image description here

Thanks in Advance

Upvotes: 0

Views: 889

Answers (2)

mnikolic
mnikolic

Reputation: 602

The cpu usage shown in top and ps are not showing exactly the same statistics.

The 'top' command by default shows the summary of cpu usage across all cores. If you press '1' in 'top', you will see the usage for each core.

The output of 'ps' shows the total cpu usage time divided by process run time. Having 100 may mean that your process used single core 100% during run time. On 4-cores cpu, the top will probably calculate around 25% total cpu usage.

The 'man' page for both commands may provide some additional details as well.

Upvotes: 1

PatrickChen
PatrickChen

Reputation: 1420

top only shows total CPU usage, that's different from which you see in details, try other cmds show more detail information.

on Linux: try mpstat -P ALL 1 cmd, show CPU load per core.
on Mac: try install htop

Upvotes: 1

Related Questions