Hey, folks.
Let's look at one of the favorites command of a system administrator or engineer to manage the system,
which is top top command is used to show the Linux processes, and it provides a real time view of their
running system.
This command shows the summary information of this system and a list of processes or threads which are
currently managed by the Linux kernel.
Now, when you run the top command or when it is executed, it actually goes into an interactive mode
and you can run the commands within that interactive mode.
Now, if you wanted to get out of the interactive mode, then you have to hit cue on your keyboard to
get out of it.
Now the usage of this command is simply by running the command top.
You don't have to be a root user, but if you want to kill a process that is owned by Root or any of
that process, but then the interactive mode of top, then you have to be their root user.
So here is a list of column that are displayed when you run the command top and let's go over one by
one.
But before we do that, let's log in are going to our Linux machine and we will run the command top
together.
All right.
I am already logged into the Linux machine.
That's confirmed.
Who am I, where I am and which machine am logged into?
Beautiful to clear that?
Now let's go ahead and simply run the command top.
All right, so right here.
Is the output of the command so starting from the top, it tells you the system uptime, the user logged
in and load average in terms of a minute, five minutes and 15 minutes.
Then it tells you the total number of tasks of running in the system totaled 193, only one or two running
to see it changes one hundred and eighty one hour sleeping, zero stop and zero zombie zero zombie or
zombie just as self means like, say, if a process has a parent process and the parent process is dead
or are then killed, then that child process becomes a zombie process.
Then we have the CPU information of the system.
Then these two last lines are about the actual physical memory and the swab, which is a virtual memory,
its usage, how much free we have, how much use, how much in love or cash.
So this is what you have the top five information.
Now let's get into the columns.
The first column is the head of it shows the task a unique process ID.
So everything we run in the next environment has.
Then you run application, it will generate processes or services.
So basically, we are looking at those processing services through this top come in and a process ID
assigned it to every process that is running or executed within the next.
And it is just like a window system as well.
When you run a process and Windows Windows operating system will assign a Process ID as well.
Then the second column is the user who is running that process or who's running that program.
Then we have PR, but this field shows the scheduling priority of the process then, and I represents
a nice value of the task.
So if you could see from the left hand side you see represents a nice value of the task.
A negative value implies higher priority and positive.
Nice value means a lower priority.
Then you have a virtual are the total virtual memory used by the task.
So if you want to know specific command, a process usage of a virtual machine or a virtual memory,
it is showing right here and this is the memory consumed by the process in the RAM.
This is for the shared memory that represents the amount of shared memory used in a task.
This single digits, this field shows a process state in the single letter form.
All right, so then we have the CPU represents the CPU usage, of course, this represents the physical
memory usage of that process, the time, the CPU time, that time the same time, but reflecting more
granularity through hundredths of a second set goes deep down into the time.
And the last one is the command or the process that actually running.
And everything else on the left hand side are the associated values to that process or that task.
All right.
So you could actually get out of this into active mode.
You see, when you run it, you don't see your prompt.
So if you wanted to get your prompt back, simply hit queue and you will get out of that interactive
mode.
All right.
Moving on, the other commands that we could use with the command is top minus you, I Absol or the
username.
This will show task process owned by a user.
So then I go to the Linux machine and if I run top minus you with my name and you will see it will only
show the processes that are owned by me or running, but by my user.
See right here, you don't see root here.
If you want to view the same thing for root, you could do top minus you root, and you will see all
the processes that are being executed by the user route.
All right, beautiful.
Moving on to the next one.
When you run top, then you could press a C while you are in the interactive mode.
This will show you the absolute path of that command.
So let's go into our Linux machine right here and it's clear the screen and just simply run tab and
right here.
When you are into an interactive mode, all you have to do is hit see on your keyboard and you will
see right here it is giving you the absolute path of every command or that process is running.
And this will tell you where exactly it is running from.
All right.
So let's cue out of it again, and let's see what's the next one?
Top then press K.
This will kill a process by process I.D. within the top session.
Oh, OK.
This is very good.
So let's run top again.
And let's say if I wanted to kill a process which is using up a lot of resources in my Linux environment,
I could go and run the kill command, which we will cover later on.
But for now, if you want to use it, if you wanted to kill a process right here, then all you have
to do is k hit K on this session and then is going to ask you, what process ID do you want to kill?
So I wanted to kill this.
For example, this top command that I'm running, which is five two one six, is simply specify the
process ID five two one six and hit enter.
And confirm and but it's killed.
That's why we are out of that top interactive mode.
All right.
Moving on to the next one, you can run tab and then uppercase M and P to short all Linux running processes
by memory usage.
OK, so let's do tab now hit Shift M for uppercase m and then shift P for process.
So to run or to sort all the running process memory, use it.
This is going to tell you which processes are the ones that are using most of your memory in the system.
And this way you could go in.
If your system is running slow, you could go in and simply kill that process.
OK.
One important note is the top commander refreshes the information every 30 seconds.
Yes.
So if you look closely, you're going to see every three seconds it refreshes the data or information
that is being displayed.
You could change that as well.
There is a setting within that tab that you could change it to, to display or to refresh every 10 seconds,
15 seconds, every one.
OK, so this is all about the top commander.
Please, please make a note of everything to be covered in the top command because you will be using
this top command an every day of your life in this system administration capacity.
And then you are managing a Linux system because this will save you a lot of headache when you are troubleshooting
issues.
I'll see you in the next lecture.