Basic Linux Administration. The command “top”

The command “top” is a valuable command in the Linux command line. As a Linux administrator this is almost always the first command I use looking for Linux issues. “top” will show you many things, and I will discuss some of the important features of “top.”

Here is an example of what you should see if you run the command “top” in the commmand line.

repsol@minime ~ $ top

top – 21:32:58 up 1:14, 1 user, load average: 0.63, 0.60, 0.54
Tasks: 155 total, 1 running, 153 sleeping, 0 stopped, 1 zombie
Cpu(s): 20.4%us, 6.6%sy, 0.0%ni, 73.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2706252k total, 1510544k used, 1195708k free, 82144k buffers
Swap: 3905532k total, 0k used, 3905532k free, 739328k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4225 repsol 20 0 222m 55m 12m S 27 2.1 7:33.22 chrome
1456 root 20 0 197m 88m 51m S 8 3.3 2:21.84 Xorg
5191 repsol 20 0 227m 57m 27m S 8 2.2 2:26.16 chrome
4031 repsol 20 0 639m 74m 37m S 5 2.8 2:28.35 chrome
2684 repsol 20 0 159m 12m 9692 S 2 0.5 0:06.29 lxterminal
4177 repsol 20 0 255m 75m 25m S 2 2.8 1:17.50 chrome
6366 repsol 20 0 2852 1172 896 R 1 0.0 0:00.11 top

OK lets go over this line by line:
1st line
top – 21:32:58 up 1:14, 1 user, load average: 0.63, 0.60, 0.54
The first interesting thing you see is 21:32:58 This is the time right now.
up 1:14 is how long the server has been up. This means 1 hour and 14 minutes.
1 user means there is one user logged in.
Load Average is the load average now, last 5 min , and last 15 min.

2nd Line:
Tasks: 155 total, 1 running, 153 sleeping, 0 stopped, 1 zombie
This is pretty straight forward. Basically 155 total possible tasks, 1 running 153 sleeping and 1 zombie.
zombie is a process where the parent processor stopped but the spawned child process didn’t die. I will cover that in a later blog.

3rd line:
Cpu(s): 20.4%us, 6.6%sy, 0.0%ni, 73.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
This is the load averages of the CPU. For the begining admin all you really need to be concerned about is teh first number 20.4% This is a ten minute average of the CPU load.
Note if you hit “1” while top is running, you will see the stats of all of the procs.
Example:
Cpu0 : 23.8%us, 6.7%sy, 0.0%ni, 68.8%id, 0.7%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu1 : 20.9%us, 7.1%sy, 0.0%ni, 72.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

4th and 5th line:
Mem: 2706252k total, 1507796k used, 1198456k free, 82836k buffers
Swap: 3905532k total, 0k used, 3905532k free, 737080k cached

The top line is Mem IN this case it shows I have 2G ram
Swap shows I have 4G swap.

Really the important thing is the second column in the Swap line 0k. That means that the OS is not swapping which is good, but if you have a server running slow and it is swapping it is a good indication a reboot could be in order. Rebooting the Linux server will clear swap.

If it is swapping, the next lines show the most offensive processes in order of the most offensive.

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4225 repsol 20 0 224m 56m 12m S 27 2.1 10:08.99 chrome
1456 root 20 0 197m 88m 51m S 9 3.4 3:01.51 Xorg
5191 repsol 20 0 227m 57m 27m S 9 2.2 3:12.96 chrome

As you can see, I am not swapping yet, but chrome is the biggest CPU draw on my system now. If I was swapping I could try to restart the chrome service or reboot the server if it is the right time to do so.

Lastly:
If you type “c” without the quotes, it will show the actual command it is running in the process list.

4031 repsol 20 0 639m 76m 37m S 14 2.9 3:13.73 /opt/google/chrome/chrome

I hope this short tutorial is helpful. If anybody has any suggestions for a basic Linux lesson hit me up, and I will gladly throw something together.

Leave a Reply