• Aucun résultat trouvé

Processes and Process Management

Dans le document URLs Referenced in This Book (Page 142-145)

Part II: The Bioinformatics Workstation

SEQRES 1 357 GLU VAL LEU ILE THR GLY LEU ARG THR ARG ALA VAL ASN 2MNR 106 SEQRES 2 357 VAL PRO LEU ALA TYR PRO VAL HIS THR ALA VAL GLY THR 2MNR 107

5.9 Playing Nicely with Others in a Shared Environment

5.9.1 Processes and Process Management

A Unix system carries out many different operations at the same time. Each of these operations, or processes, has a unique process ID that allows the user or the administrator to interact with that process directly.

There are a minimum number of processes that run on a system regardless of whether you actively initiate them. Each shell program, whether idle or active, has a process ID attached to it. Several system (or root) processes, sometimes known as daemons, are constantly active on the system. These processes often lie in wait for you to initiate some activity they handle: for instance, printing files, sending email, or initiating a telnet session.

Above and beyond this minimal system activity level are any processes you initiate by typing a command or running a program. The Unix kernel manages these processes, allocating whatever resources are available to the processes according to their needs.

Each process uses a percentage of the processing capacity of the system's CPU or CPUs. It also uses a percentage of the system's memory. When the processes running on a machine require more than 100% of the CPU's capacity to execute, each individual process will execute more slowly. While Unix does an extremely good job of juggling hundreds of processes that run at the same time without having the machine roll over and die, eventually you will see a situation where the load on the machine increases to the point that the machine becomes useless. The operating system uses many techniques to prevent this, such as limiting the absolute number of processes that can be started and swapping idle jobs out of memory. Even on a single processor system, it's possible to have multiple processes running concurrently as long as there is enough space for both jobs to remain in memory. At the point at which the CPU has to constantly wait for data to get loaded from the swap space on the hard drive, you will see a great drop in efficiency.

This can be monitored using the top command, which is described in Section 5.9.1.3. Many machines are more limited by lack of memory than they are by a slow CPU, and it's often now more cost-effective to put money into additional RAM than to buy the latest, greatest, and fastest CPU.

5.9.1.1 Checking the load average

Usage: w

Safari | Developing Bioinformatics Computer Skills -> 5.9 Playing Nicely with Others in a Shared Environment

http://safari.oreilly.com/main.asp?bookname=bioskills&snode=58 (1 of 9) [6/2/2002 8:59:45 AM]

All Books Search

The w command is available on most Unix systems. This command can show you which other users are logged into the system and what they are doing. It also shows the current load average on the system.

The standard output of the w command looks like this:

2:55pm up 37 days, 4:50, 4 users, load average: 1.00, 1.02, 2.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT jambeck tty1 22Jan99 37days 3:55m 0.06s startx jambeck ttyp0 :0.0 Wed 5pm 1:34m 0.22s 0.22s -csh

jambeck ttyp3 :0.0 21Feb99 3:47 9.05s 8.51s telnet weasel god ttyp2 around 2:52pm 0.00s 0.55s 0.09s create world

The first line of the output is the header. It shows the time of day, how long the machine has been up, how many users are logged in, and what the load average on the system has been for the last 1 minute, 5 minutes, and 15 minutes. The load average represents the fractional processor use on the system. If you have a single processor system and a load average of 1, the system is being used at optimal capacity. A four-processor system with a load average of 2 is being used at only half of its capacity. If you log in to a system and it's already being used at or beyond its capacity, it's not polite to add other processes that will start running right away. The batch or at commands can set up a process to start when resources become available.

The information displayed for each user is the username, the tty name, the remote host from which the user is logged in, the login time, the idle time, the JCPU and PCPU times, and what the user is doing.

5.9.1.2 Listing processes with ps

Usage: ps [options]

ps produces a snapshot of what the processor is doing at the moment you issue the command. Depending on what your computer is doing at the time, typing ps at the prompt should give output along the lines of:

PID TTY TIME CMD

36758 ttyq10 0:02 tcsh 43472 ttyq10 0:00 ps

42948 ttyq10 4:24 xemacs-20

42967 ttyq10 1:21 fermats-last-theorem-solver

Most of ps 's options modify the types of processes on which ps reports and the way in which it reports them. Here are some of the more useful options:

a

Lists every command running on the computer, including those of other users l

Produces a long listing of processes (process memory size, user ID, etc.) f

Lists processes in a "tree" form, showing related processes

Notice that you don't need to preceed the option with a dash. There are actually a couple of dozen options for ps ; check info ps to see which options are supported by your local installation.

5.9.1.3 top

Usage: top -[options]

The top command provides real-time monitoring of processor activity. It lists processes on the system, sorted by CPU usage, memory usage, or runtime. The top screen looks like this:

4:34pm up 37 days, 6:29, 4 users, load average: 0.25, 0.07, 0.02 42 processes: 39 sleeping, 3 running, 0 zombie, 0 stopped

CPU states: 42.9% user, 6.4% system, 0.0% nice, 51.0% idle

Mem: 39092K av, 38332K used, 760K free, 13568K shrd, 212K buff

Safari | Developing Bioinformatics Computer Skills -> 5.9 Playing Nicely with Others in a Shared Environment

http://safari.oreilly.com/main.asp?bookname=bioskills&snode=58 (2 of 9) [6/2/2002 8:59:45 AM]

Swap: 33228K av, 20236K used, 12992K free 8008K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND

516 jambeck 15 0 4820 3884 1544 R 0 30.4 9.9 4:23 emacs-fgyell 415 root 9 0 10256 9340 888 R 0 15.5 23.8 161:41 /usr/X11R6/b 10756 cgibas 5 0 716 716 556 R 0 2.3 1.8 0:01 top-ci

The header is similar to the output of w but more detailed. It gives a breakdown of CPU and memory usage in addition to uptime and load averages. The display can be changed to show a variety of fields. The default configuration of top is set in the user's .toprc file or in a systemwide /etc/toprc file.

Here are the top options:

-d

Updates with a frequency of delay -q

Refreshes without any delay, running at the highest possible priority -s

Runs in secure mode, with its most potentially dangerous commands disabled -c

Prints the full command line instead of just the command you're running -i

Ignores all processes except those currently running

While top is running, certain interactive commands can be entered, unless they are disabled from the command line.

The command i toggles the display between showing all processes and showing just the processes currently running. k kills a process. It prompts you for the process ID of the process to kill and the signal to send to it. Signal 15 is a normal kill; signal 9 is a swift and deadly kill that can't be ignored by the process. r changes the running priority of a process, implementing the renice command discussed in Section 5.9.1.5. It prompts you for the process ID and the new priority value for the job.

5.9.1.4 Signaling processes with kill

Usage: kill [-s signal | -p ] [ -a ] PID

The kill command lets you terminate a process abnormally from the command line. While kill can actually send various types of signals to a process, in practice it's most often used in the form kill PID or, if that fails to kill the process, kill -9 PID.

On most systems, kill -l lists the available types of signals that can be sent to a process. It's sometimes useful to know that jobs can be stopped and restarted with kill -s STOP and kill -s CONT. [7]

[7] Discussion of the other signals can be found in any of the comprehensive Unix references listed in the Bibliography.

A PID is usually just the numerical process ID, which you can find with the ps or top commands. It can also be a process name, in which case a group of similarly named processes can be addressed. Another useful form of PID is -n process group ID, which allows the kill command to address all the processes in a group simultaneously.

5.9.1.5 Setting process priorities with nice and renice

Usage: nice -n [val command arg]

Usage: renice-n[incr][-g|-p|-u]id

Processes initiated on a Unix system run at the maximum allowed priority unless you tell them to do otherwise. The nice and renice commands allow the owner of a process, or the superuser, to lower the priority of a job.

If limited computing resources are shared among many users and computers are used simultaneously for computation

Safari | Developing Bioinformatics Computer Skills -> 5.9 Playing Nicely with Others in a Shared Environment

http://safari.oreilly.com/main.asp?bookname=bioskills&snode=58 (3 of 9) [6/2/2002 8:59:45 AM]

and interactive work, it's polite to run background jobs (jobs that run on the machine without any interactive interface) with a low priority. Otherwise, interactive jobs such as text editing or graphical-display programs run extremely slowly while background jobs hog the available resources. Jobs running at a low priority are slowed only if

higher-priority processes are running. When the load on the system is low, background jobs with low priority expand to use all the available resources.

You can initiate a command at a low priority using nice. n is the priority value. On most systems, this is set to 10 by default and can range from 1-19, or 0-20. The larger the number, the lower the priority of the job, of course.

The renice command allows you to reset the priority of a process that's already running. incr is a value to be added to the current priority. Thus, if you have a background process running at normal priority (priority 1) and you want to lower its priority (by increasing the priority number), you can enter renice -n 18 to increase the priority value to 19.

You can also input a negative number to put the job at high priority, but unless you are root, you are limited to raising its priority to 1. The renice options, -p, -g, and -u, cause renice to interpret id as a process ID, a process group ID, or a user number, respectively.

Dans le document URLs Referenced in This Book (Page 142-145)