Hardware is getting amazingly fast. But sometimes it seems like
software gets slower faster than hardware speeds up.
So why do so many apps feel poky?
In this series, I'll look at some of the ways you can examine your
system to see what's taking up resources, and offer some tips on
slimming your system down so it runs faster.
I'll start with two of the basic command-line applications
for measuring performance: top and ps.
When you suspect something is running away with system resources,
top should be your first recourse. It gives you a screen
that updates every couple of seconds, showing you a list
of the processes that are hogging the most CPU.
The fields, in order, are:
- process ID -- you can use this for killing the process or finding
out more about it
- the user who started the process, most often either you or root
- The priority of the process. This usually doesn't mean much on Linux
- How "nice" the process is -- whether it will step aside when other
processes need to do some work. Most normal programs will be at zero;
a positive number up to 20 means the process will give way to
other processes, while a negative number means an important
process (often part of the kernel) which will take priority
over normal programs.
- The process's virtual memory size. This is virtually meaningless --
I'll write more about memory in a future article.
- The amount of memory the process is currently using in memory.
Again, there are caveats and this may not mean quite what you
think it does.
- Shared memory: how many shared libraries the process is using.
- A single letter code representing the process's status.
R means it's actively running. S means sleeping, but you'll also see it
for lots of running processes, if top happens to check in between
updates. T means it's temporarily stopped (you can stop a process
by typing Control-Z in the terminal where you started it).
D means it's in uninterruptible sleep, perhaps because it's
waiting for a device to respond. Finally, Z means it's a zombie
process: one that has exited but its parent process isn't paying
attention any more. You can't get rid of zombie processes, but
they don't take up any significant system resources.
- What percentage of the CPU the process is currently taking
- What percentage of memory the process is using
- How much CPU time the process has accumulated, in hundredths of a second.
- The name of the process
Top has some useful options, too. For instance, if you want to run
top just once and save its output into a file, you can do it like this:
top -b -n 1
When you're running top interactively, you can change the way it sorts:
type M to sort by memory use rather than CPU, T to sort by total time,
or P to go back to sorting by CPU. Those letters are all capitalized.