1. Overview

The Linux top command is a very powerful tool for monitoring system performance. It helps when checking the system load and utilization and this can prevent a lot of issues. For example, we can analyze the behavior of different processes, detect bottlenecks, and make decisions based on this information.

In this tutorial, we’ll see a simple usage of the top command and learn how to manipulate its output format to be more human-readable.

2. Using the top Command

The top command by default provides an interactive output that lists the running processes and their respective CPU and memory usage. It automatically refreshes the output and updates the values periodically as they change. This gives the user visibility into the system’s performance and resource consumption.

One of the advantages of top utility is that it’s fairly straightforward to use:

$ top

top - 14:54:31 up 1 min,  1 user,  load average: 1.76, 2.17, 2.27
Tasks:  12 total,   1 running,  11 sleeping,   0 stopped,   0 zombie
%Cpu(s):  5.6 us,  3.8 sy,  0.0 ni, 89.5 id,  0.1 wa,  0.0 hi,  1.0 si,  0.0 st
MiB Mem :  96570.6 total,  16933.1 free,  18452.3 used,  61185.2 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  77278.0 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND         
      1 root      20   0  165220  10520   8244 S   0.0   0.0   0:00.16 systemd         
    256 root      20   0   16132   7812   6844 S   0.0   0.0   0:00.04 systemd-journal 
    561 systemd+  20   0   25252  12460   8520 S   0.0   0.0   0:00.11 systemd-resolve 
   1122 root      20   0   14896   6512   5708 S   0.0   0.0   0:00.07 systemd-logind  
   2197 root      20   0    9468   5940   3808 S   0.0   0.0   0:00.01 bash            
   2380 root      20   0   10616   3772   3196 R   0.0   0.0   0:00.00 top 

Here, the output is divided into two parts:

  • upper part: dashboard
  • lower part: task list

The dashboard displays in the first five rows a summary of some system information:

  • system uptime
  • total number of processes
  • average CPU usage
  • average memory utilization

So, the dashboard provides an overview that we can quickly look at.

On the other hand, the task list provides a breakdown of the processes and their respective resource consumption. Thus, we’re able to monitor performance and track activity with finer detail.

3. top Human-Readable Format

The default output of top shows sizes in the Kibibyte unit, so it might not be easy to interpret. However, we can change this default format by pressing the e key while on the main screen:

$ top

top - 05:37:45 up 10 min,  1 user,  load average: 4.39, 3.08, 2.41
Tasks:  12 total,   1 running,  11 sleeping,   0 stopped,   0 zombie
%Cpu(s):  8.0 us,  1.7 sy,  0.0 ni, 89.8 id,  0.0 wa,  0.0 hi,  0.6 si,  0.0 st
MiB Mem :  96570.6 total,  10829.5 free,  12615.3 used,  73125.8 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  83024.8 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND         
      1 root      20   0  161.3m  10.3m   8.0m S   0.0   0.0   0:00.15 systemd         
    257 root      20   0   15.8m   7.8m   6.8m S   0.0   0.0   0:00.04 systemd-journal 
    561 systemd+  20   0   24.7m  12.3m   8.5m S   0.0   0.0   0:00.11 systemd-resolve 
   1123 root      20   0   14.5m   6.3m   5.5m S   0.0   0.0   0:00.07 systemd-logind  
   2194 root      20   0    9.2m   5.7m   3.6m S   0.0   0.0   0:00.01 bash            
   2386 root      20   0   10.4m   3.7m   3.2m R   0.0   0.0   0:00.00 top

Here, we used the top command and then pressed e while on the screen. Consequently, we see sizes in the task list area are in Mebibyte. Depending on the components, this is usually a more convenient format for humans.

Since the dashboard area is still in the KiB format, we can convert it into MiB by pressing the Shift+e key combination on the main screen:

top - 05:38:31 up 11 min,  1 user,  load average: 2.47, 2.74, 2.32
Tasks:  12 total,   1 running,  11 sleeping,   0 stopped,   0 zombie
%Cpu(s):  6.4 us,  2.8 sy,  0.0 ni, 90.0 id,  0.1 wa,  0.0 hi,  0.6 si,  0.0 st
GiB Mem :     94.3 total,     10.0 free,     12.8 used,     71.5 buff/cache
GiB Swap:      0.0 total,      0.0 free,      0.0 used.     80.6 avail Mem 

As we can see, the output format of the dashboard is now adjusted. We can keep changing the unit of the format between KiB, MiB, GiB, and so on, by pressing e for the task area and Shift+E for the dashboard area.

Finally, we can save the configuration of the output display by pressing W. This enables us to later use the command with the current configured state.

4. Conclusion

In this article, we’ve discussed the basics of using top and learned how to format its output to be more user-friendly.

In summary, top is a command-line utility to monitor system performance and resource utilization. It provides a comprehensive output with information about the overall system as well as a breakdown of each individual process.

The default output of the command shows sizes in KiB format. However, we can modify this by pressing the e or Shift+E keys. The lowercase e modifies the output in the task area, while the Shift+E modifies it in the dashboard area.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.