Viewing Processes


A process is something that exists entirely behind the scenes. When the user runs a program, one or many processes might be started, but they're usually invisible unless the user specifically chooses to manipulate them. You might say that programs exist in the world of the user, but processes belong in the world of the system.

Processes can be started not only by the user, but also by the system itself to undertake tasks such as system maintenance, or even to provide basic functionality, such as the GUI system. Many processes are started when the computer boots up, and then they sit in the background, waiting until they're needed (such as programs that send mail). Other processes are designed to work periodically to accomplish certain tasks, such as ensuring system files are up-to-date.

You can see what processes are currently running on your computer by running the top program. Running top is simply a matter of typing the command at the shell prompt.

As you can see in Figure 17-1, top is comprehensive in the information it provides and can be a bit overwhelming at first sight. However, the main area of interest is the list of processes (which top refers to as tasks).

image from book
Figure 17-1. The top program gives you an eagle's eye view of the processes running on your system.

Here's an example of a line taken from top on my test PC, shown with the column headings from the process list:

PID  USER  PR  NI  VIRT  RES  SHR S %CPU %MEM   TIME+  COMMAND  5499 root  15   0 78052  25m  60m S  2.3  5.0  6:11.72 X

A lot of information is presented here, as described in Table 17-1.

Table 17-1. The top Program Process Information

Column

Description

PID

The first number is the process ID (PID). This is the unique number that the system uses to track the process. This comes in handy if you want to kill (terminate) the process. I'll explain how this is done in the next section of this chapter.

USER

This column lists the owner of the particular process. As with files, all processes must have an owner. A lot of processes will appear to be owned by the root user. Some of them are system processes that need to access the system hardware, which is something only root is allowed to do. Other processes are owned by root for protection; root ownership means that ordinary users cannot tamper with these processes.

PR

This column shows the priority of the process. This is a dynamic number, showing where the particular process is in the CPU queue at the present time.

NI

This column shows the “nice” value of the process. This refers to how charitable a process is in its desire for CPU time. A high figure here (up to 19) indicates that the process is willing to be interrupted for the sake of other processes. A negative value means the opposite: the process is more aggressive than others in its desire for CPU time. Some programs need to operate in this way, and this is not necessarily a bad thing.

VIRT

This column shows the amount of virtual memory used by the process.[1]

RES

This column shows the total amount of physical memory used.[1]

SHR

This column shows the amount of shared memory used. This refers to memory that contains code that is relied on by other processes and programs.

S

This column shows the current status of the task. Generally, the status will either be sleeping, in which case an S will appear, or running, in which case an R will appear. Most processes will be sleeping, even ones that appear to be active. Don’t worry about this; it just reflects the way the Linux kernel works. A Z in this column indicates a zombie process (a child of a process that has been terminated).

%CPU

This column shows the CPU use, expressed as a percentage.[2]

%MEM

This column shows the memory use, again expressed as a percentage.[2]

TIME+

This column shows a measure of how long the process has been up and running.

COMMAND

This shows the actual name of the process itself.

%CPU

This column shows the CPU use, expressed as a percentage.[2]

%MEM

This column shows the memory use, again expressed as a percentage.[2]

TIME+

This column shows a measure of how long the process has been up and running.

COMMAND

This shows the actual name of the process itself.

[1]Both VIRT and RES are measured in kilobytes unless an m appears alongside the number, in which case you should read the figure as megabytes.

[2]The %CPU and %MEM entries tell you in easy-to-understand terms how much of the system resources a process is taking up.

This list will probably be longer than the screen has space to display, so top orders the list of processes by the amount of CPU time the processes are using. Every few seconds, it updates the list. You can test this quite easily. Let your PC rest for a few seconds, without touching the mouse or typing. Then move the mouse around for a few seconds. You'll see that the process called X leaps to the top of the list (or appears very near the top). X is the program that provides the graphical subsystem for Linux, and making the mouse cursor appear to move around the screen requires CPU time. When nothing else is going on, moving the mouse causes X to appear as the number one user of CPU time on your system.

Tip 

Typing d while top is running lets you alter the update interval, which is the time between screen updates. The default is three seconds, but you can reduce that to one second or even less if you wish. However, a constantly updating top program starts to consume system resources and can therefore skew the diagnostic results you're investigating. Because of this, a longer, rather than shorter, interval is preferable.

It's possible to alter the ordering of the process list according to other criteria. For example, you can list the processes by the quantity of memory they're using, by typing M while top is up and running. You can switch back to CPU ordering by typing P.

image from book
Renicing A Process

You can set how much CPU time a process receives while it's actually running. This is done by renicing the process. This isn't something you should do on a regular basis, but it can prove very handy if you start a program that then uses a lot of system resources and makes the system unbearably slow.

The first thing to do is to use top to spot the process that needs to be restrained and find out its PID number. This will be listed on the left of the program's entry on the list. Once you know this, press r, and then type in the PID number. You'll then be asked to specify a renice value. The scale goes from –20, which is considered the highest priority, to 19, which is considered the lowest. Therefore, you should type 19. After this, you should find some responsiveness has returned to the system, although how much (if any) depends on the nature of the programs you're running.

You might be tempted to bump up the priority of a process to make it run faster, but this might not work because of complexities in the Linux kernel. In fact, it might cause serious problems. Therefore, you should renice with care and only when you must.

image from book




Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net