Вы находитесь на странице: 1из 6

Guides Add comment s

Understanding the Top command on Linux


Aug
28
2012
top
Share

Tweet
Article by AlexioBash published on his website
about ArchLinux in italian.
Know what is happening in real time on your systems is in my
opinion the basis to use and optimize your OS. On ArchLinux or
better on GNU/Linux in general thetop command can help us,
this is a very useful system monitor that is really easy to use,
and that can also allows us to understand why our OS suffers
and which process use most resources. The command to be run
on the terminal is:
$ top
And well get a screen similar to the one on the right:
Lets see now every single row of this output to explain all the information found within the screen.
1 Row top

This first line indicates in order:
current time (11:37:19)
uptime of the machine (up 1 day, 1:25)
users sessions logged in (3 users)
average load on the system (load average: 0.02, 0.12, 0.07) the 3 values refer to the last minute, five minutes
and 15 minutes.
2 Row task

The second row gives the following information:
Processes running in totals (73 total)
Processes running (2 running)
Processes sleeping (71 sleeping)
Processes stopped (0 stopped)
Processes waiting to be stoppati from the parent process (0 zombie)
3 Row cpu

The third line indicates how the cpu is used. If you sum up all the percentages the total will be 100% of the cpu. Lets
see what these values indicate in order:
Percentage of the CPU for user processes (0.3%us)
Percentage of the CPU for system processes (0.0%sy)
Percentage of the CPU processes with priority upgrade nice (0.0%ni)
Percentage of the CPU not used (99,4%id)
Percentage of the CPU processes waiting for I/O operations(0.0%wa)
Percentage of the CPU serving hardware interrupts (0.3% hi Hardware IRQ
Percentage of the CPU serving software interrupts (0.0% si Software Interrupts
The amount of CPU stolen from this virtual machine by the hypervisor for other tasks (such as running
another virtual machine) this will be 0 on desktop and server without Virtual machine. (0.0%st Steal Time)
4 and 5 Rows memory usage


The fourth and fifth rows respectively indicate the use of physical memory (RAM) and swap. In this order: Total
memory in use, free, buffers cached. On this topic you can also read the following article
Following Rows Processes list


Post ed by linuxari at 21:30 Tagged wit h: gnu linux, linux, memory, process, real
t ime, running processes, sessions, syst em load average,syst em
monit or, upt ime
8 Responses to Understanding the Top command on Linux

And
as last thing ordered by CPU usage (as default) there are the processes currently in use. Lets see what information we
can get in the different columns:
PID lID of the process(4522)
USER The user that is the owner of the process (root)
PR priority of the process (15)
NI The NICE value of the process (0)
VIRT virtual memory used by the process (132m)
RES physical memory used from the process (14m)
SHR shared memory of the process (3204)
S indicates the status of the process: S=sleep R=running Z=zombie (S)
%CPU This is the percentage of CPU used by this process (0.3)
%MEM This is the percentage of RAM used by the process (0.7)
TIME+ This is the total time of activity of this process (0:17.75)
COMMAND And this is the name of the process (bb_monitor.pl)
Conclusions
Now that we have seen in detail all the information that the command top returns, it will be easier to understand the
reason of excessive load and/or the slowing of the system.
A good alternative to TOP is HTOP , an evolution of top with features really amazing.
Popular Posts:
Linux Games: Bravada
Whats new in Red Hat Enterprise 7
Whats new in Red Hat Enterprise 7
Configuring your console pager
Configuring your console pager
Find me on Google+
1. imo says:
08/29/2012 at 15:56
atop is *way* better and should replace top as a standard
Reply
2. Frederick Wrigley says:
08/29/2012 at 17:55
I use top, but more often use htop, which is like top on steriods. Its likely in most repos for any distro.
Reply
3. Duncan says:
08/30/2012 at 01:53
OK, so you say what each line means, but at that level, the information is pretty much there for the reading in the labels or
the top manpage, anyway.
The sort of questions I remember asking myself when I first started were things like:
OK, we have Load. I know what average means and I /think/ I know what load means, and it goes up as the system gets busier,
and down as the system is less busy, but what does 0.02 (the load 1 minute average in the example above) actually MEAN? It
OBVIOUSLY cant be percent CPU load, because thats reported too, and its WAYY too low for that!
I KNOW its load average, because I can READ the labels. And its easy enough to find that the three numbers are 1/5/15 minute
averages. What I did NOT know was what load average was.
FWIW, if I understand correctly but not getting /too/ technical. load, on Linux/Unix, refers the the number of threads that would
be ready to run if given CPU time at that instant, as opposed to those that couldnt run, because theyre waiting for some event.
For instance, as I type this, firefox is spending a lot of time waiting for me to type the next letter in the textbox, so its mostly idle
and not runnable, thus not contributing to load very much. The instantaneous load can be seen on tops task line as running
(note that at the moment the measurement is taken, top itself is running, so top should always report at least one running, more if
anything else is running at that instant as well, also note that running actually means runnable, its quite possible to have a
running load well above the actual number of CPU cores available on your system, so its NOT reporting actually RUNNING,
but runnable, despite the label). For those who like a file interface, its also available as the procs_running line near the
bottom of /proc/stats. Also see /proc/loadavg for the averages, a runnable/total threads ratio as the 4th number, and I dont know
what the 5th is.
Load average indicates how many threads were runnable on average during the time in question, and a one-minute load average
of 1.00, under ideal conditions, would mean that exactly one cpu core was running at 100% during the last full minute, which on a
single-core system would be 100% CPU utilization (ideally). Of course in actuality, a 1.00 one minute load average isnt likely to
keep a single CPU core at 100% usage for the full minute, because for a small fraction of that minute there was likely a 2.0
instantaneous load as the average was updated and as other system tasks did their thing, which means there was also a fraction of
time when nothing was ready to run and that core was idle. So to get close to 100% CPU utilization on a single core in practice
takes a bit more, say a 1.5 load average.
And of course on a modern multi-core, the load necessary to fully utilize all cores goes up along with the number of cores. On my
6-core bulldozer, for instance, a load average of 6.00 would be the (ideal/theoretical) minimum required to keep the CPU fully
occupied, but in practice, a load average of 9 or so would be more efficient at it. But get a load average more than about double
your number of cores (and of course for CPUs that have it, theres hyperthreading to figure in as well, noting that each
hyperthread is counted like a physical core would be, tho theres differences), and your CPU is probably a bottleneck (altho it
can be a storage bottleneck as well, since i/o-wait is counted as load). Additionally, the higher the load average goes, the more real
CPU cycles the kernel takes to manage scheduling, so while the kernel can /manage/ a load of several hundred per core as long as
memory and other resources dont run out, its spending a lot of time switching tasks in and out instead of actually doing them,
and is therefore going to take longer in wall-time to complete those tasks, than it would have if load were limited to say 3 per core.
(With tasks like kernel builds, its possible to tell the system how many jobs to run in parallel. A kernel build is a really nice
example here, as if allowed to schedule unlimited jobs and given enough memory, it can paralllel several hundred, perhaps over a
thousand. I do that here routinely and get up to about 600, tho it takes my full 16 gig of ram and goes into swap to do so. But
while its fun to watch the runnables climb, even if limited a bit so it doesnt swap TOO much, letting it schedule say 20 parallel
make jobs per core, 120 jobs total on my 6-core, does take longer in wall time to complete than something more reasonable, say
four jobs per core, 24 jobs total on my 6-core.)
OK, so people reading this comment can now /understand/ what the load average numbers are, and can make better guesses about
the tasks line (tho the zombie entry needs more explanation). But what about the rest? The title of the article suggests the reader
will /understand/ top when hes done reading it. Hardly! If they can read labels (and if they couldnt, how could they read this
article) and had run the command before, they barely know more about it whan when they started, let alone UNDERSTAND it.
Now the article needs to be expanded to do pretty much what I did for load, to nearly every single entry (the uptime, etc, seems
pretty self explanatory). What does user vs system vs nice vs wait vs actually MEAN, for instance. Whats do nice and
priority mean in the Linux scheduling context, and how do they relate to each other? If the memory line says I have 0 free
memory, does that mean the systems about to crash? (Hint: No, the free in free memory doesnt mean what one might
intuitively /think/ it means, in this context.) We have the names and the numbers, now we just need to UNDERSTAND them,
something the article title and opening blurb suggest the article will help with, but which it unfortunately did a rather poor job at.
Wheres the understand part? =:^(
Reply
4. woo says:
08/30/2012 at 14:50
there are some lines in Italian that slipped through untranslated:
%CPU indica la percentuale del processo sul carico sulla cpu (0.3)
%MEM indica la percentuale del processo sul carico della RAM (0.7)
TIME+ indica il tempo di attivit del processo (0:17.75)
COMMAND indica il nome del processo (bb_monitor.pl)
I _do_ understand them but for the sake of consistency, please translate those
Reply
linuxari says:
08/30/2012 at 15:25
Thanks Woo.
Fixed
Reply
5. ammaro says:
12/02/2012 at 15:18
thanks for your explanations, but which is better htop or top
Reply
linuxari says:
12/02/2012 at 19:55
You can find top in every Linux system, while you have to install htop that IMO give much more
information

Вам также может понравиться