The Linux TOP Command

LINUX TOP

The Linux TOP command provides valuable monitoring and troubleshooting information. However, there is a lot of information in a very condensed format and it can be tricky to sort through what is important and what isn’t.

This post was written using Ubuntu 16.04.2 LTS and TOP 3.3.10.

TOP SCREENSHOT

THE TOP OF TOP

1. top - 18:45:48 up 14 days,  2:31,  1 user,  load average: 0.00, 0.00, 0.00
2. Tasks: 127 total,   1 running, 126 sleeping,   0 stopped,   0 zombie
3. %Cpu0  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0
4. KiB Mem :  1014372 total,   490596 free,    50532 used,   473244 buff/cache
5. KiB Swap:        0 total,        0 free,        0 used.   907684 avail Mem        [

The first few lines of output from TOP give you a system overview. It shows up time, users, load average, CPU and memory statistics.

Line 1 shows the system time and up time (14 days). We see one user is logged in and our system load average is 0.

Note that load average is a 1:1 ratio per CPU. If you have 4 cores and your load average is 4 you are using your CPU to full capacity. If you go over to say 6 or 8 for a few minutes occasionally this should not be an issue. However, if your load average is 8 on a 4 core system for any lengthy period of time you can expect your system to run slow.

Line 2 shows Tasks (or processes). We can see here we have 127 total processes, 1 running, and 0 stopped or zombie processes. A running process is actively doing using CPU and a sleeping process is waiting for something to do. We’ll see later how to see which PIDs are in what state. Pressing t will alternate the Tasks display

A stopped process is a suspended process. This process has been suspended manually (CTR-Z) or could be being traced. Neither of these are a big deal, but if you have more than one or two stopped processes and you don’t know why there may be something goofy going on.

A zombie process is the coolest sounding process, but the uncoolest to actually have. This is a process that has finished (exited), but is still on the process table for some reason. Here again, having one or two isn’t going to cause you issues, but if you have more than a few it probably indicates something gone awry.

Line 3 here is our CPU stats. If you are on a multicore system you are going to have a line for each core. While top is running pressing 1 will switch between one line per core and one line for all CPUs.

There are some detailed CPU stats on this line also.

%Cpu0 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

** Line 4** are the memory statistics. These are a lot more obvious than the CPU stats.

KiB Mem : 1014372 total, 490596 free, 50532 used, 473244 buff/cache

** Line 5** is related to swap space. This should normally be pretty low. I don’t seem much swapping on any current system. If used is high you probably need more RAM.

PROCESS DETAILS

I am generally only concerned with a few of these details. I set TOP on my systems to display the following information:

  PID  PPID %CPU %MEM S    RES   UID COMMAND
13732  1025  0.0  0.7 S   6668     0 sshd: larntz [priv]
 1025     1  0.0  0.5 S   4724     0 /usr/sbin/sshd -D
    1     0  0.0  0.5 S   5464     0 /sbin/init

CONCLUSION

There are a lot more features and options available when using TOP, but this covers most of what you need to know when looking at a system. If you are troubleshooting and you find an questionable area of the system you may need to refer to the TOP man page or use other tools to continue tracking the problem.

REFERENCES

TOP manpage

linuxhowtos.org