Previous Table of Contents Next


Module 94
nice

DESCRIPTION

The external nice command executes a specified command at a lower CPU priority than normal. Thus its name is derived from the fact the command is being nice to the rest of the users. The lower your priority the slower your program runs and the longer it takes to complete.

The super-user can increase the priority of a command by using nice. Instead of specifying -n, a --n is given.

The nice value of a process can be viewed using the ps -l command. The NI column displays the nice value. The higher the value the lower the CPU priority (the slower the process executes).

COMMAND FORMAT

Following is the general format of the nice command.

       nice [ -n ] command [ options ] [ arguments ]

Options

The following option may be used to control how nice functions.

-n Decreases the scheduling priority by the value of n. The value of n can be from 1 to 19.
If you do not specify a number, 10 is used.

Arguments

The following arguments may be passed to the nice command.

command The name of any command you normally execute. This command's process ID is assigned a lower priority level.
options The options to be used by the command.
arguments The arguments to be used by the command.

C shell
The C shell uses a + to lower your CPU priority and a - to increase it. The nice command is an internal command.

DIAGNOSTICS AND BUGS

If you specify a number greater than 19, 19 is used.

RETURN CODES

The exit status of command is returned.

APPLICATIONS

The nice command is beneficial in controlling the use of the CPU. If you are running large jobs, such as document formatting or other various CPU hogs, you should use nice. These CPU and/or IO intense jobs slow down the interactive jobs unless you lower their priority. This allows you to process large CPU intensive jobs while continuing to perform interactive tasks without as much delay.

TYPICAL OPERATION

In this activity you use the nice command to lower the priority of a command. Then you check the priority by using the ps command. Begin at the shell prompt.

1.  Type nice find / -name core -print > /dev/null & and press Return. This places the find command in background at a lower priority.
2.  To check the priority of the find command type ps -l and press Return.
    cj> ps -l
    F S  UID  PID  PPID  C PRI NI   ADDR   SZ    WCHAN TTY    TIME COMD
    1 R   60  4947 4771 14 181 20 bedc81  820          tty3p3 0:00 ps
    1 S   60  4771 1     0 168 20 a02ea0  500  1abd6a0 tty3p3 0:02 ksh
    1 S   60  4945 4771  3 148 30 594ab0  392   897380 tty3p3 0:03 find

The NI field is the NICE value for each process. The higher the value the nicer the command.
3.  Type kill 4945 and press Return to kill the find process. Replace 4945 with the PID number for your find process.
4.  Turn to Module 96 to continue the learning sequence.


Previous Table of Contents Next