top – display tasks and system status in Unix

top is a basic Unix command which is very useful for observing the current state of your Unix system, by default presenting you the list of top users of your system's resources – CPU shares and memory.

Basic usage of the top command

By default, you run top without any parameters, and it shows you a full screen (or full window of your terminal) with the current status of your system and a list of processes using most of its CPU:

Output of the top command explained

These are the elements which default top output consists of:

Unix system uptime and average load

This is the line of top which confirms how many hours (or even days!) your system has been up, shows you the number of logged in users, and reports the average system load numbers for the last minute, 5 minutes and 15 minutes.

us – User CPU time. The time the CPU has spent running users’ processes with default priorities

sy – System CPU time. The time the CPU has spent running the kernel and its processes

ni – Nice CPU time. The time the CPU has spent running users’ proccess that have been prioritized up using nice command

wa – I/O wait. Amount of time the CPU has been waiting for I/O operations to complete

hi – Hardware IRQ. The amount of time the CPU has been servicing hardware interrupts

si – Software Interrupts. The amount of time the CPU has been servicing software interrupts

st – Steal Time. The amount of CPU ’stolen’ from this virtual machine by the hypervisor for other tasks (such as running another virtual machine) – a fairly recent addition to the top command, introduced with the increased virtualization focus in modern operating systems

Physical memory usage stats

Memory stats line gives you a summary of how much physical memory you have on your system, and how much of it is currently used or available for the use.

Modern Linux systems are buffering quite a lot for improved performance, which means you rarely get to see all your physical RAM free – the more your system stays up and running, the more of its recently used data ends up being buffered.

In this line, you can see how quite a bit is taken up by the buffers:

Mem: 4051792k total, 4026104k used, 25688k free, 359168k buffers

Swap usage stats

Swap statistics highlight how actively your system uses the swap space – most of it should not be used on a healthy system, although seeing substantial amount of swap memory cached is quite normal. Bear in mind that these are caches held in physical memory, so in this example these 2.8Gb of cached swap is responsible for most of the 4Gb physical RAM taken up and reported as used in the above stats for memory

Swap: 4096492k total, 24296k used, 4072196k free, 2806484k cached

List of the tasks (processes) running on your system

This is the main part of the top output, which looks like this (output is abridged):