man page: man top
The top command gives a general overview about the system resources and which process consumes how much of them. This can be useful in multiple scenarios, e.g. if your system gets slow (detect swapping) or containers do not start/crash because of not enough memory.
Checkout also the general overview post: Useful Linux commands
Usage of top
Here is an example how it looks
top - 12:39:19 up 23 days, 16:10, 1 user, load average: 0.06, 0.04, 0.00
Tasks: 133 total, 1 running, 132 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 3844.4 total, 91.2 free, 1368.1 used, 2385.1 buff/cache
MiB Swap: 100.0 total, 89.5 free, 10.5 used. 2400.5 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1642655 jenkins 20 0 4779128 1.3g 21044 S 0.0 33.3 76:35.85 java
44794 root 20 0 1417312 21084 4324 S 0.0 0.5 49:03.65 contain+
357 root 20 0 220888 4112 2744 S 0.0 0.1 10:06.39 rsyslogd
2670340 u143 20 0 169808 4544 1704 S 0.0 0.1 0:00.00 (sd-pam)
1 root 20 0 165952 9752 7280 S 0.0 0.2 51:05.64 systemd
442 root 20 0 157832 1432 1320 S 0.0 0.0 0:35.50 rngd
150 root 20 0 131448 72240 71040 S 0.0 1.8 31:04.61 systemd+
2651597 systemd+ 20 0 88104 6096 5352 S 0.0 0.2 0:00.20 systemd+
169 root 20 0 21264 3284 2880 S 0.0 0.1 0:10.02 systemd+
2670358 u143 20 0 16400 5604 4204 S 0.0 0.1 0:00.11 sshd
2670336 root 20 0 16208 7892 6640 S 0.0 0.2 0:00.07 sshd
2670339 u143 20 0 16044 8504 7172 S 0.0 0.2 0:00.18 systemd
363 root 20 0 14608 6216 5472 S 0.0 0.2 19:16.49 systemd+
520 root 20 0 13656 5956 5760 S 0.0 0.2 3:06.71 sshd
367 root 20 0 13580 2920 2856 S 0.0 0.1 0:14.17 wpa_sup+
The first line shows how much processes (tasks) are running and in which state they are, i my case i have 133 Tasks, one is running and the rest sleeps.
The next line shows the overall CPU usage, it is 0.1 percent in my example. There are 2 ways to display CPU usage in top command, either irix or solaris mode. In irix mode 1 cpu in your system is 100%, so in a multi core system you can have percentages over 100%, and in solaris mode this percentage number is just divided by the number of cores available (you can switch with I).
The next two lines show total memory usage for memory and swap. In my example i have 3844.4 mb in memory and 100 mb swap in total. 91.2/89.5 mb are free , 1368.1/10.5 are used and 2385.1 of the memory are filled with buffer/cache data which means they probably can be made usable. The last information in that section is the available memory, e.g. for starting a new process, which is 2400.5 mb in my case.
After that general information the process table shows per process the resource consumption. You can change list ordering with < and > keys which moves the ordering in the columns. My example is ordered by VIRT (virtual memory).
The table shows the process id, running user, memory consumption, cpu consumption running command etc.
If you interested in more details of the shown fields and how they are calculated you can check the man page (also online under https://man7.org/linux/man-pages/man1/top.1.html).
Leave a Reply