Be on Top of your Game- A look at the Linux top command
The “top” command is simple but yet, one of the powerful system monitoring and analysis tool used on Linux and Unix-Like operating systems. It mostly comes pre-installed on Linux distributions ready to be used for tracking and monitoring real-time running processes on your Linux system.
As a beginner Linux System Administrator, making sense of the output of the this command the first time becomes somehow very challenging looking at it cryptic output. With this two (2) part series of article in which we look at the output and the usage of the “top” command, I will therefore, be walking you the audience through the command output and as well some usage steps.
For this article, I am going to be using a distribution of Linux known as Elementary OS, with a version of 5.1.7 Hera. So without much I do, let’s first check the version of the “top” command running on our system by running “top” with the -hv options or flags after which we would then move on to looking at the output of the top command and how to make meaning of each row within the output. The usage aspect of the command be look at in the second part of the article.
$ top -hv
The procps-ng is the package providing the type of the “top” command I am using with this demo, and the numbers right after it is the release version. To move on, I will run the “top” command without any arguments or flags so we can see the output and as well get to learn the various rows as seen from the command output.
Having seen the “top” command output, let’s us now take each row starting from the very top with the top row and analyze for better understanding and comprehension of the command output.
• 23:57:30 – Current time as at the time the “top” command was issued.
• up 13:14 – Tells how long the system has been up since the last reboot
• 1 user – Tells how many users are currently logged into the system. In this case only one (1)
• load average: 0.56, 0.51, 0.55 – Tells the load average on the system for the last 1, 5 and 15 minutes respectively.
To explain a bit further, from your top command output, when you see something in the 1 minute row that is higher than that of the 5 or 15 minute row, then your load is increasing, and the reverse is true also. Also, a load of 1.00 could either mean max capacity or 50% used capacity, and all this is based on the cores you have running on the system in question. For example, a single core system with load of 0.00 means, no traffic or load at all, but with a load of 1.00 means full capacity has be reached. Another example will be of a dual core system with a load of 1.00, though we see 1.00 just as before with the single core system does not mean we have reached the full capacity of the core but rather, we are at 50% usage capacity since we are running of f of dual core and with dual core, we are running two CPUs and this case only is full.
Therefore, as sysadmin, when troubleshooting, you are to understand that, seeing the numbers alone does not solve your problem, since 0.56, 0.51, 0.55 by itself means absolutely nothing, but will mean something if core count is known and are very sure it’s a core-bound workload.
• 293 total – Tells of the total processes on the system
• 1 running – Tells of how many processes are running on the system. In this case only one (1)
• 211 sleeping – Tells of how many processes are sleeping on the system
• 0 stopped – Tells of how many processes has been stopped. Which in this case zero (0)
• 0 zombie – Tells of how many zombie are there on the system. In this case zero (0)
A zombie as its known is process whose execution is actually finished but still has an entry in the process table for some reasons.
• 2.4 us – Tells of CPU percentage used by user processes on the system
• 1.3 sy – Tells of CPU percentage used by system processes on the system
• 0.0 ni – Tells of processes with the CPU nice upgrade to them
• 95.9 id – Tells of the percentage of CPU in idle time or not being used
• 0.0 wa – Tells of the processes in CPU percentage that are in I/O operation waiting to be serviced
• 0.0 hi – Tells of the CPU in percentage that is in hardware interrupts service
• 0.1 si – Tells of the CPU in percentage that is in software interrupt service
• 0.0 st – Tells of the amount of CPU in percentage that has been stolen from the machine by the hyper-visor for running other tasks.
Since both the fourth and fifth rows talks about memory with respect to Physical and Swap memory, I am going to lump them together with my next screenshot and then give the breakdown.
In order as from left to right is Total Memory on the system, Free Memory, Used Memory and Buffed/Cached Memory respectively; and this is being measured in Kilobyte, but of course, you can convert into megabyte or gigabyte if you so wish.
Also within seen in the “top” command output, are processes running on the system and sitting right on top of the processes is row with columns giving indications of what is going in terms of CPU usage by the various processes listed below. Let’s therefore look at the various columns one by one to get an understanding of what each column says about a process.
• PID – Tells the process ID of the running process (1157)
• USER – Tells of the user who owns the process (root)
• PR – Tells of the priority level at which the process is running at (20)
• NI – Tells of the “nice” value assigned the process (0) the niceness value that can be assigned to process is from -19 to 20. -19 being the highest and 20 being the lowest
• VIRT – Tells of the virtual memory being used by the process (1306572)
• RES – Tells of the physical memory being used by the process (121568)
• S – Tells of the state in which the process is: S=sleep, R=running, Z=zombie
• %CPU – Tells of the CPU percentage usage of the process (9.2)
• %MEM – Tells of the Memory percentage usage of the process (0.7)
• TIME+ – Tells of the total time of activity of the process (28:46.28)
• COMMAND – Tells of the name of the process (Xorg)
On this note we draw the curtains down to first part of this series where we looked at the output of the “top” command. We would be looking at the second part, where I will walk you through sample usage of the “top” command. Check out the link below, it is an evolved top called htop: