Understanding the Top command on Linux

In Linux the top command provides a dynamic real-time view of a running system to the user. It provides a summary report or information about process or threads currently being managed by the kernel. You can install and use htop application later for these information in details. In this tutorial I will provide you a general information about the command top

How to execute top:

To execute top command just open your terminal window and after writing top hit enter.

After executing the command you will able to see a screen like below

top-cmd

Now we will learn what is the meaning of these output

The first line of the result gives you the following information:

top-cmd-1st

  • current time (17:27:10)
  • uptime of the machine (up 1 day, 10:33)
  • users sessions logged in (2 users)
  • average load on the system (load average: 0.01, 0.02, 0.05) the 3 values refer to the last minute, five minutes and 15 minutes.

The second row gives the following information:

top-cmd-2nd

  • Processes running in totals (77 total)
  • Processes running (1 running)
  • Processes sleeping (76 sleeping)
  • Processes stopped (0 stopped)
  • Processes waiting to be stoppati from the parent process (0 zombie)

The third line indicates how the cpu is used. If you sum up all the percentages the total will be 100% of the cpu. Let’s see what these values indicate in order:

top-cmd-3rd

  • Percentage of the CPU for user processes (0.3%us)
  • Percentage of the CPU for system processes (0.0%sy)
  • Percentage of the CPU processes with priority upgrade nice (0.0%ni)
  • Percentage of the CPU not used (99.7%id)
  • Percentage of the CPU processes waiting for I/O operations(0.0%wa)
  • Percentage of the CPU serving hardware interrupts (0.0%hi) — Hardware IRQ
  • Percentage of the CPU serving software interrupts (0.0%si) — Software Interrupts
  • The amount of CPU ‘stolen’ from this virtual machine by the hypervisor for other tasks (such as running another virtual machine) this will be 0 on desktop and server without Virtual machine. (0.0%st — Steal Time)

The fourth and fifth rows respectively indicate the use of physical memory (RAM) and swap. In this order: Total memory in use, free, buffers cached.

top-cmd-4th

Below are some shortcuts for top commands. Use these while running the top command.

l –To display or to hide load average line
t –To display or to hide task/cpu line
1 –To display or hide all other CPU’s
m –to display or to hide RAM and SWAP details
s –To change the time interval for updating top results(value is in sec’s)
R –To sort by PID number
u — Press u then username to get only that user process details
P –To sort by CPU utilization
M –To sort by RAM utilization
c –To display or hide command full path
r –To renice a process, press r then the PID no then the renice value to renice a process.
k –To kill a process, press k then PID number then enter to kill a process
w –To save the modified configuration permanently.
q –To quit the top command.
h –for getting help on top command

The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

Leave a Reply