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.

Basic Linux Adminsitration CLI

Hello this is my first blog entry. I have had a request for help for beginning command line help. There is probably too much to learn for one blog, so I will try, and write several beginner blogs.

Definitions:
The shell is a way to interface with your operating system. It is popular because it is a quick way to make changes. It is powerful, and you can get a lot of info quickly through the shell. Other names for a shell are: BASH, Terminal, or Console (sometimes cli (comand line)).

Username: user account on the PC
Hostname: the name of your PC
ls equals list -there are many options for ls. To see them you can type “man ls”

Lets get started:
Open a shell -The shell by default should give you a prompt. Preceding the curser you should see your username@hostname:$ . It should be waiting for some input.

By default you are in your default home directory /home/

Mine looks like this:
adrenaline@system76:~$

Now type something: ls
This will give you a list of all fo the cotents in your home directory.
One of the directories should be “Desktop”.

Now type: cd Desktop
then: ls
Now you should be in /home//Desktop.
To know for sure type: pwd (pwd is present working directory)
Mine looks like this.
adrenaline@system76:~/Desktop$ pwd
/home/adrenaline/Desktop

Now type:ls
You should see all of the files on your deskop here in a list format.

Now to go back one directory type: cd ..

If you get lost changing directories, you can simply type “cd” with no options and it will take you back your your home directory.

One thing to note: Linux/Unix is case sensitive on the command line.
azloco and Azloco are two different words in Linux.

This is all for now. If anybody has any beginning tutorial questions, you can email me at adrenaline@azloco.com or catch me in IRC irc.freenode.org #ubuntu-us-az.