Understanding top Command CPU Usage

Last updated: September 18, 2023 | Bobbin Zachariah

The top command in Linux offers a dynamic view of CPU processes in real time, providing a crucial snapshot of system health. This guide dives deep into interpreting CPU usage in top output.

CPU Line

When you launch top, you'll first notice the summary section at the top. In that section see a line that starts with %Cpu(s):, followed by several metrics. Like:

%Cpu(s): 0.5 us, 0.5 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
top command cpu usage

Each metric provides insights into different facets of CPU activity:

us (User CPU time):

This shows the percentage of CPU utilization that occurred while executing at the user level (applications). High user CPU time can indicate that your applications or processes are busy.

sy (System CPU time):

Represents the percentage of CPU utilization that occurred in the kernel or system level. A high system time can indicate that the OS is busy with system-level tasks, possibly due to I/O waits, system calls, or other kernel operations.

ni (Nice CPU time):

This displays the percentage of CPU utilized by user-level processes with a positive nice value. The nice value is a user-set priority level: a higher nice value means lower priority.

id (Idle):

Represents the percentage of time the CPU was not used by any process. A very low idle value indicates the system is heavily loaded.

wa (I/O wait):

Shows the percentage of time the CPU is waiting for I/O operations to complete. High I/O wait can indicate disk bottlenecks or other I/O issues.

hi (Hardware IRQ):

The time the CPU served hardware interrupts. It's usually very low unless you have hardware issues or a very busy device.

si (Software IRQ):

Time spent serving software interrupts. Like hi, this is typically low.

st (Steal Time):

This is relevant in virtualized environments. It represents the percentage of time a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor.

Understanding %CPU

In the list of processes below the summary, you'll see individual CPU usage for each process. This is represented as a percentage of a single CPU core:

4234  user1     20   0  103332   9128   6772 R  50.0  0.7   0:00.53 process_name

%CPU Column

Represents the percentage of CPU used by the process. In a multi-core environment, this can exceed 100% (e.g., 200% would mean the process is utilizing two cores completely). This means

So, if you're in a multi-core environment:

  • A process using 100% means it's fully utilizing one core.
  • A process showing 200% is utilizing two cores completely, and so on.

In Irix mode, which is the default behavior of the top command, the CPU usage is displayed for each process as a percentage of a single CPU core. Switching top out of Irix mode (by pressing Shift + I) will display the CPU usage as a percentage of the total CPU capacity, which makes the total usage across all processes max out at 100%.

For individual processes, high %CPU values indicate processes that are currently using a lot of the CPU's processing power.

On a machine with hyper-threading enabled, the CPU usage shown is indeed per logical CPU (or thread), not the physical core. You can use lscpu command to get information about the number of threads per core.

By default, the processes are sorted by the %CPU column in descending order. This means that the process consuming the most CPU resources will appear at the top of the list. Pressing M will sort processes by memory usage. You can always revert to sorting by %CPU by pressing P.

If you are using multi-threaded applications -H option helps to see the CPU and memory usage of each individual thread, rather than just the aggregated usage of the entire process.

Interpreting the Data

If User CPU time (us) is high, it usually means that user applications or processes are consuming a lot of CPU. You might want to check if this is expected behavior.

High System CPU time (sy) can suggest the OS is overloaded with system-level tasks or is spending a lot of time context switching.

A high I/O wait (wa) often indicates that your system is disk-bound, meaning it's spending more time reading/writing to disk, possibly due to insufficient RAM or slow disk speed.

In virtualized environments, if Steal Time (st) is high, it indicates that your virtual machine is waiting for the host machine's CPU resources, which might be serving other VMs.

For individual processes, high %CPU values indicate processes that are currently using a lot of the CPU's processing power.

Taking Action:

If a particular process is consistently consuming high CPU, consider restarting that service or application. Investigate its logs or configuration for potential reasons for high CPU consumption.

Remember that the top command gives a snapshot of the current state. To analyze patterns over time, tools like sar or monitoring solutions like Nagios or Zabbix can be more appropriate. Unlike the traditional top command, you can use htop to display a comprehensive overview of system resources, including a visual representation of CPU usage across all cores.



Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment