How to Use the Linux top Command (and Understand Its Output)

A terminal prompt on a Linux laptop.Fatmawati Achmad Zaenuri / Shutterstock

The Linux top command is one of the pillars of Unix-like Operating systems. Its utility display is full of useful information about your system’s running processes and resource usage. But did you know that it also supports color, highlighted and even basic graphics?

A dashboard full of information

The upper control exists since 1984, and there are many variations. For this article, we are running Ubuntu 18.04 with all fixes applied and version 3.3.12 of top. We also crossed everything on two other test computers, one running Fedora and the other Manjaro.

The default upper display collects as much information as possible from the terminal window. Information is a prerequisite for administration, so it’s a good thing. One of the traits of a good system administrator is the ability to identify emerging issues and deal with them before they affect service. top gives you a dashboard of many different system metrics that help you do just that.

The display is best described as functional, rather than intuitive, and abbreviations abound. When you meet a top for the first time, it feels cramped, cryptic, and off-putting. However, by pressing a few keys, you can adjust the content and format of the display to suit what is important to you.

Check your version from the top

To check the version of your top, type the following terminal window:

top -v

top -v in a terminal window.

If your version is far behind 3.3.12, it may not support all of the features that we will cover.

The default display

You can start at the top by typing the following and pressing “Enter”:

High

high in a terminal window.

The default view contains two information areas: the summary area (or dashboard) and the task area (or process list). By default, top updates its display every three seconds. You will notice a slight flicker when it does.

The first line of numbers on the dashboard includes the time, the operating time of your computer, the number of people connected and what the average load has been for the last one, five and 15 minutes. The second line indicates the number of tasks and their states: run, stop, sleep or zombie.

The third line displays the following central processing unit (CPU) values:

we: Time the processor spends executing processes for people in “user space”.
sy: Time spent executing system kernel space processes.
or: Time spent executing processes with a manually defined value value.
id: Processor idle time.
Washington: Time the processor spends waiting for I / O to complete.
Hello: Time spent on maintenance of hardware interruptions.
if: Time spent maintaining software interruptions.
st: Time lost due to running virtual machines (“flight time”).

The fourth line shows the total amount (in kibibytes) of physical memory, and how much is free, used, and buffered or cached.

The fifth line shows the total amount (also in kilobytes) of swap memory, and the amount available, used and available. The latter includes memory which should be recoverable from caches.

The column headers in the list of processes are as follows:

PID: Process ID.
USER: The owner of the process.
PR: Priority process.
OR: The great value of the process.
VIRT: Amount of virtual memory used by the process.
RES: Amount of resident memory used by the process.
SHR: Amount of shared memory used by the process.
S: Process status. (See the list below for the values ​​that this field can take).
% CPU: Part of the processor time used by the process since the last update.
% SAME: The share of physical memory used.
TIME +: Total CPU time used by the task in hundredths of a second.
ORDER: The name of the command or the command line (name + options).

Memory values ​​are displayed in kilobytes. The COMMAND column is off screen, on the right. It did not match the image above, but we will see it shortly.

The process status can be one of the following:

RE: Uninterrupted sleep
A: Operation
S: Sleeping
T: Plot (stopped)
Z: Zombie

Press Q to exit the top.

Display scrolling

You can press the Up or Down, Start, End and Page Up or Down arrows to move up and down and access all the processes.

Press the left or right arrow to move the list of processes laterally. This is useful to see all the columns that do not fall within the limits of the terminal window.

In the image below, we pressed the right arrow several times to display the COMMAND column.

Modification of digital units

Let’s change the display units to sensitive values. Press the capital letter E to cycle through the units used to display the memory values ​​in these options: kibioctets, megabytes, gibioctets, tebioctets, pebioctets and exbioctets. The unit used is the first element in lines four and five.

Press “e” in lower case to do the same for the values ​​in the process list: kibibytes, mebibytes, gibibytes, tebibytes and pebibytes.

We pressed E to set the memory units of the dashboard to gigabytes and “e” to set the memory units of the process list to megabytes.

Modifying the content of the summary

You can change the display settings for dashboard rows or delete them completely.

Press l to activate or deactivate the charge summary line (the first line). We have removed the charge summary line in the image below.

If you have a Multicore CPU, press 1 to change the display and see the individual statistics for each CPU. There are four processors on our computer. We press 1 to see how hard everyone works.

Of course, this takes up more screen space in the terminal window.

You can press “t” to switch the CPU displays to single ASCII graphs that show the percentage of use of each CPU.

For each CPU, the top displays three numbers and the graph. From left to right, the numbers are as follows:

The combined percentage between us and ni (user space + tasks with pleasant non-standard parameters).
The percentage sy (nucleus space).
The total (rounded to an integer value).

Press “t” again to change the graph display to solid block characters.

Press “t” again to completely remove the processor display and the job summary line.

Press “m” to scroll through the memory and swap the memory lines between the different display options. The first press replaces the statistics with an ASCII graph.

Another press changes the graphic to block the characters.

Press “m” once more to completely remove the CPU lines.

If desired, you can see the processor and memory graphics simultaneously. Just press “t” and “m” until you get the combination you want.

Color and highlight

You can press “z” to add color to the display.

When you think of the top, you probably don’t think of the colorful screens and ASCII graphics, but they are integrated.

Press “y” to highlight the running tasks in the process list. Press “x” to highlight the column used to sort the list of processes. You can switch between highlighting bold and inverted text by pressing “b”.

Sort by columns

By default, the list of processes is sorted by the% CPU column. You can change the sort column by pressing the following:

P: The% CPU column.
M: The% MEM column.
NOT: The PID column.
T: The TIME + column.

In the image below, the list of processes is sorted by the PID column.

See the full command line

Press “c” to toggle the COMMAND column between displaying the process name and the full command line.

To display a “tree” of processes launched or generated by other processes, press V.

See Process for a single user

Press “u” to see the processes for a single user. You will be asked to enter the name or UID.

Type the name of the UID of the person you want to monitor. We are going to type “dave” and press “Enter”. Now, the only processes in the task area belong to the user dave.

View only active tasks

Press I to display only active tasks.

Tasks that have not consumed any processor since the last update will not be displayed.

Define the number of processes to display

Press “n” to limit the display to a certain number of lines, whether the tasks are active or not. You will be asked to indicate the number of processes to display.

We typed 10 and hit Enter, so 10 processes appear in the task area.

Renice a process

You can press “r” to change the beautiful value (priority) for a process. You will be asked to enter the process ID. Simply press Enter to use the process ID for the task at the top of the process window. We type 7800, which happens to be the process ID of a Firefox instance.

After pressing Enter, you are prompted to enter the new interesting value to apply to the process. We type 15, then press Enter.

The new cool value is immediately applied to the process.

RELATED: How to set process priorities with nice and renice on Linux

Kill a process

Press “k” to kill a process. You will then be asked to enter the process ID you wish to kill. In fact, you can send any signal to the process. We are going to kill process 7879, which has stopped responding.

You will be able to enter the signal you want to send. You can specify it by name or number. If you just press Enter, the top sends the signal SIGTERM (kill).

As soon as you press Enter, the signal is sent to the process.

RELATED: How to kill processes from the Linux terminal

Display customization

You can also customize the colors and columns displayed. We are going to change the color used for the prompts, the default color of which is red.

Press capital Z to access the color settings page. The upper part of the screen shows the colors used by the different display elements. To indicate which display item you want to change, tap one of the following options, which are case-sensitive:

S: Summary data area.
M: Messages and prompts.
H: Column headers.
T: Information on the tasks in the process list.

We press M to modify the prompts.

To choose a color, press one of the following numbers:

0: Black.
1: Red.
2: Green.
3: Yellow.
4: Blue.
5: Magenta.
6: Cyan.
7: White.

We press 6 to use cyan.

Press Enter to save your settings. The input prompts will now be the color you have selected.

We can also modify the columns displayed in the field management screen. Press F to access the field management screen.

The displayed fields are accompanied by an asterisk (*) and are highlighted in bold. Press the up and down arrows to move the highlight to the list of fields.

If you move the highlight to the bottom of a column, it will appear at the top of the next (unless you are at the bottom of the last column). If you move it to the top of a column, it will appear at the bottom of the previous one (unless you are at the top of the first column).

We moved the highlight to the COMMAND entry, then pressed “d” to remove the asterisk (*). We then went to the UID entry and pressed “d” to place an asterisk next to this entry. This means that the COMMAND column will not be displayed, but the UID column will be.

While the highlight is on the UID column, we press “s” to sort the process list on the UID column.

Press Enter to save your settings, then press “q” to exit the Field Management screen.

The UID column replaced the COMMAND column and the list of processes is sorted by it.

Alternative display mode

It works best in full screen mode. Press A to display four zones in the list of processes, then press “a” to move from one zone to another.

Each zone has a different collection of columns, but each is also customizable via the field management screen. This gives you the option of having a custom full screen display showing different information in each area and the ability to sort each area by a different column.

Other strikes

Here are some other keys you might find useful at the top:

W: Save your settings and customizations so that they are always in effect the next time you start them.
re: Define a new display refresh rate.
Space: Force top to update its display now.

Best banana

As we have seen, top has a whole repertoire. Other programs, like htop, were inspired by it, but each has their own vision of things.

However, top is installed everywhere. When you go to companies to consult networks or servers, you will often be told that nothing can be changed on live servers. The client establishes the rules, so you must use what is already installed.

Even if you prefer a different monitoring tool, you should know more. Sooner or later, you will likely find yourself in a situation where you will only have access to all of this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.