- In this video,
I will show you how to manage processes using top.
And in order to do so,
I'm starting top with elevated privileges
to ensure that I have access to everything.
So what do we see?
Well, the top interface
and the top interface is called top
because it's sorts processes by CPU activity.
So you will always see the busiest process
listed as number one.
In the five headlines,
you get some additional information about the system.
It starts with some uptime information,
number of users that are logged in.
And then it's giving you a load average.
The load average is giving information
about the current workload of the system.
And it's expressed in three numbers
for the last one, five and 15 minutes.
Now, the number reflects the average number of processes
that has been asking for attention.
And you know what?
Let's just start a couple of processes.
(quiet typing)
I am going to run three background processes
because it's more interesting to see
that top is actually showing something.
So as you can see,
we have the three dd processes
that are listed as the most active processes.
And you can see the load average slowly climbing up.
It's an average for the last one minute.
So it will take about one minute
until we will see a three right here.
Now, the load average is an indicator
of the performance health of your system.
Big question is,
what is good and what is bad?
Well, it all depends on the number of CPUs in your system.
And from this interface,
we don't see directly how many CPUs there are.
The third line is just a summary of all the CPUs
that are available, but if you press 01,
then you get one line for every single CPU.
So this is a two CPU system.
So what does that mean?
Well, two CPUs means
that if we have processes
that are asking 100% of CPU attention,
the two CPUs can only have two processes at the same time.
So if the load average is higher than the number of CPUs
that you have in your system,
then you need to investigate what is going on.
It's not necessarily a bad situation
but you should investigate what is going on.
So the second line,
on the second line we can see the number of tasks
that is running.
The interesting part.
The interesting part here
is that we can see four of them are actively running.
Running is for processes
that recently have asked CPU attention.
And we have 244 sleeping,
they are not creating any significant workload.
No stopped ones, no zombies.
A zombie is a process
that has gone into an unmanageable state
and you shouldn't see them at all.
And if you see them,
well, probably the best thing
is either to wait until they go away
or to reboot your system to force them to go away.
Then we have the CPUs line.
Remember if I press 01,
then I see a summary for all CPUs
and I can press one again to toggle
for a display that is showing one line
for every single CPU.
In the CPUs line,
we can see information about what exactly the CPU is doing.
So we can see about 16% in us,
us is user space.
User space are non-privileged processes.
It's typically tasks that are executed by an ordinary user.
We have 80% in sy, sy is system space.
That is where drivers are involved.
And I can tell you given the workload of dd,
where we use dd from one interface to another interface
there it's understandable that the activity in system space
is quite high, but normally
you should see your activity more in the user space.
A very important indicator is id, id is for the idle loop.
It will tell you how much time your CPU is spending
in doing nothing.
And the other important parameter is a wa,
wa means waiting for I/O
and waiting for I/O means that your system is waiting
for your disc channel to take care of processing the data.
If you have a high number in wa
then there is definitely something not alright
in your storage channel.
And that's a candidate for optimization.
The other parameters are not so very important.
So keep an eye on us, si, id and wa
and you can get a pretty good impression
of what is going on.
Then we have a line for the memory usage.
So this system as four gigabytes in total
and about 1.2 gigabytes free.
Also, we can see about 1.3 gigabytes used
and 1,400 megabytes in buffer and cache.
Now, what is this buffer and cache?
Simple.
It's all about memory
and this system has four gigabytes of memory.
Now, Linux is using memory for cache,
if it is not needed by anything else.
Cache is used for recently requested files.
And the thing is, if the file is stored in cache,
the next time that somebody needs it,
it can be serviced from cache.
And that makes your system fast.
If the memory is not needed for anything else,
your data will be kept in cache forever.
At some point, your system will reach the state
where the memory is needed for something else.
And then the Linux kernel is going to clear data from cache,
if it has not recently been used.
Last, we can see the Swap parameter.
The Swap parameter indicates the usage of Swap space.
Swap space is emulated RAM on disc.
So it's kind of overflow and it is useful
in cases where you are completely running out of RAM
because then memory pages can be moved to Swap
and your system can still continue functioning.
Swap is a little bit slower
but the Linux kernel is dealing
with Swap in a very smart way.
It'll only move inactive memory pages to Swap,
if that is possible.
And if you only have inactive memory pages in Swap
then that just cleans up your RAM
and you can use your RAM for more useful stuff.
And that, in general, is considered to be good.
As you can see, we have two gigabytes of Swap
and two gigabytes of Swap are free
and nothing is used.
The last parameter is not about Swap.
This is about a total memory.
So the total memory is set to
more than two gigabytes of available memory.
Now, the thing that is a little bit confusing here
is the relation between free memory and available memory.
Now, what is the relation?
Free memory is memory
that's currently not used for anything at all.
You won't always see so much free memory
because if your system has been up for a longer period
then you'll have less free memory available.
That is because memory will always be used
for caching files.
Now in cache, the Linux kernel keeps track
of memory pages that are allocated to cache
that have not recently been used.
That's what we call, inactive cache.
And available memory is a summary of inactive cache
and free memory.
The thing about inactive cache
is that if the memory is needed by something else,
well, you can just clear the inactive cache.
And that makes it,
we have 2.3 gigabytes of available memory.
Right in the lowest part of the top interface,
we can see these processes.
For every process, the PID,
the user that has started to process
and some more information.
The interesting information right here is the CPU percentage
and the memory.
That's a percentage of CPUs that the process is running
and the percentage of memory.
And now we can see the names of these processes.
Let me go out of top for now.
We have seen enough.