Skip to main content

The top command

The top command can be used to monitor the usage of CPUs, memory, and swap space of the OS. It can also be used to monitor processes. The command output is sorted based on the CPU time.

Command output example:

top - 10:12:21 up 5 days, 22:31,  4 users,  load average: 1.00, 1.00, 0.78
Tasks: 731 total, 1 running, 730 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.7 us, 0.0 sy, 0.0 ni, 98.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 257841.3 total, 1887.5 free, 45581.6 used, 210372.2 buff/cache
MiB Swap: 8192.0 total, 8188.7 free, 3.3 used. 210450.4 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
908076 mysql 20 0 193.0g 42.4g 44088 S 100.3 16.8 228:10.34 mysqld
823137 root 20 0 6187564 83772 51636 S 6.6 0.0 6:36.12 dockerd
822938 root 20 0 3278696 58500 35420 S 0.7 0.0 38:37.69 containerd
1483 root 20 0 239280 9260 8136 S 0.3 0.0 0:19.16 accounts-daemon
928343 root 20 0 9936 4576 3240 R 0.3 0.0 0:00.04 top
......

Parameters in line 1:

ParameterDescription
10:12:21The current system time.
up 5 daysThe number of days for which the system runs continuously since last startup.
4 usersThe number of the online users.
load averageThe average system workloads in the past 1 minute, 5 minutes, and 15 minutes.

Parameters in line 2:

ParameterDescription
totalThe number of processes.
runningThe number of processes that are in the running state.
sleepingThe number of processes that are in the sleeping state.
stoppedThe number of processes that are in the stopped state.
zombieThe number of processes that are in the zombie state.

Parameters in line 3:

ParameterDescription
usThe percentage of CPU time spent in running user space processes.
syThe percentage of CPU time spent in running system processes.
niThe percentage of CPU time spent in running the processes of which priorities are changed.
idThe percentage of CPU time spent idle.
waThe percentage of CPU time spent in wait.
hiThe percentage of CPU time spent in handling hardware interrupts.
siThe percentage of CPU time spent in handling software interrups.
stThe percentage of CPU time spent on the hypervisor.

Pay attention to values in this line. If the value of us is large, user space processes consume much CPU time. If the value of us is larger than 50% for a long time, applications must be tuned in time. If the value of sy is large, system processes consume much CPU time. This may be caused by improper OS configuration or OS bugs. If the value of wa is large, I/O waits are high. This may be caused by high random I/O access or an I/O bottleneck.

Parameters in line 4:

ParameterDescription
totalThe amount of memory.
freeThe amount of free memory.
usedThe amount of used memory.
buff/cacheThe amount of memory that is used as buffers and cache.

Parameters in line 5:

ParameterDescription
totalThe size of swap space.
freeThe size of free swap space.
usedThe size of used swap space.
avail MemThe size of swap space that has been cached.

Parameters in the process list:

ParameterDescription
PIDThe process ID.
USERThe owner of the process.
PRThe priority of the process. A smaller value indicates a higher priority.
NIThe nice value of the priority. A positive integer indicates that the priority of the process is being downgraded. A negative integer indicates that the priority of the process is being upgraded. The value range is -20 to 19 and the default value is 0.
VIRTThe amount of virtual memory occupied by the process.
RESThe amount of physical memory occupied by the process.
SHRThe amount of shared memory occupied by the process.
SThe status of the process. The value can be:
- S: sleeping
- R: running
- Z: zombie
- N: The nice value of the process is a negative value.
%CPUThe percentage of the CPU time used by the process.
%MEMThe percentage of the memory occupied by the process.
TIME+The total CPU time used by the process.
COMMANDThe command that the process is running.