top command in Linux
top command
Display tasks and system status in Unix/Linux.
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.
In this line:
- 13:29:09 is the current time
- 2 days, 7:13 is the uptime
- 4 users shows how many users currently use your system
- 0.07 – average load for the last minute
- 0.02 – average load for the last 5 minutes
- 0.00 – average load for the last 15 minutes
Unix tasks stats
Here you can see how many tasks are currently running on your system. Tasks here mean processes, and the main listing will show you the task names (in the COMMAND column) and the PIDs.
CPU(s) status
Current CPU state, averaged for the number of CPUs installed in your system, is represented in this line:
Here are the explanations for each parameter:
- 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:
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
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):
As you can see from this list, you’re given all the vital information about each process running on your Unix system:
- PID – process ID
- USER – username for the owner of each process
- PR – process priority (RT means a Real Time priority class – used for system processes)
- NI – priority set by nice utility
- VIRT – the amount of virtual memory used by a process: code, data and shared libraries plus pages that have been swapped out
- RES – the resident part of a process – how much of it resides in the physical memory (non-swapped memory)
- SHR – shows you the size of potentially shared memory segments for a process
- S – the current state of each process
- %CPU – percentage of the time shares CPU spends running a particular process
- %MEM – percentage of the physical memory of your system which is used by each process
- %TIME+ – total time CPUs spent running each process
- COMMAND – a command used to initiate each process.
I’ll be sure to revisit and expand this page at some later stage.
See also
- htop – interactive process viewer (better than top)
- uptime – find out how long the system has been up
- uname – print Unix system information
- basic Unix commands
- Unix Commands
- Unix System Monitoring Commands
top command
Display tasks and system status in Unix/Linux.
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.
In this line:
- 13:29:09 is the current time
- 2 days, 7:13 is the uptime
- 4 users shows how many users currently use your system
- 0.07 – average load for the last minute
- 0.02 – average load for the last 5 minutes
- 0.00 – average load for the last 15 minutes
Unix tasks stats
Here you can see how many tasks are currently running on your system. Tasks here mean processes, and the main listing will show you the task names (in the COMMAND column) and the PIDs.
CPU(s) status
Current CPU state, averaged for the number of CPUs installed in your system, is represented in this line:
Here are the explanations for each parameter:
- 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:
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
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):
As you can see from this list, you’re given all the vital information about each process running on your Unix system:
- PID – process ID
- USER – username for the owner of each process
- PR – process priority (RT means a Real Time priority class – used for system processes)
- NI – priority set by nice utility
- VIRT – the amount of virtual memory used by a process: code, data and shared libraries plus pages that have been swapped out
- RES – the resident part of a process – how much of it resides in the physical memory (non-swapped memory)
- SHR – shows you the size of potentially shared memory segments for a process
- S – the current state of each process
- %CPU – percentage of the time shares CPU spends running a particular process
- %MEM – percentage of the physical memory of your system which is used by each process
- %TIME+ – total time CPUs spent running each process
- COMMAND – a command used to initiate each process.
I’ll be sure to revisit and expand this page at some later stage.
See also
- htop – interactive process viewer (better than top)
- uptime – find out how long the system has been up
- uname – print Unix system information
- basic Unix commands
- Unix Commands
- Unix System Monitoring Commands