Basic Linux Commands: The Top Command

Basic Linux Commands: The Top Command
Page content

History

The Linux top command has roots in the VMS operating system’s topcpu. As it is seen in today’s Linux, top was created for BSD in 1984 by William Lefebvre. Since its creation, top has been re-released many times for many operating systems (and many licenses). But throughout, the purpose of top has remained the same - to report current running tasks in real-time. Because top runs real time, as processes change the listing changes.

What top reports

When top is run there are two portions of the window: The top portion is the summary section. This is where you’ll find an overall system summary. This summary consists of total system memory, total running tasks, total zombied tasks, total users, load average, etc. The bottom portion is the process section. This shows all current running processes. Both sections are updated in real time.

A typical process entry contains the following important information:

  • task PID (process identification number)
  • user associated with the processes
  • virtual memory used
  • % CPU used
  • % memory used
  • uptime of command
  • command

Some of the information isn’t as helpful to the average administrator. The above listing will give you everything you need to know about a process.

Top in action

Top memory confusion

There is always some confusion about memory usage with top. If you look at the sample image above you will see that top is only reporting 7996k of free memory. But if you were on that system you would know that there is more memory available than that. Instead of believing what you see you have to understand what is actually being reported. Here’s how it looks:

  • The first section (in our sample showing 772764k total)
  • The second section (in our sample showing 764768k used)
  • The third section (in our sample showing 7996k free)

Here’s how it really breaks down:

  • The first line shows active memory which is any memory being used by any application.
  • The second line shows inactive memory which is any memory that is not being used but has yet to be marked as available for applications to use. This means the system is holding this memory for use by applications that will need it. In other words the memory that is available for applications, in our example, is 764768.

Final thoughts

Top is an incredibly useful tool and should be a permanent part of your Linux administrators' toolkit. Get to know top and allow it to help you make your administrative tasks easier.

This post is part of the series: Linux Command Line

If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname