Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

nohup(1)

renice(1)

nice(2)

nice(1)

NAME

nice − run a command at non-default priority

SYNOPSIS

nice [- priority_change] command [command_args]

DESCRIPTION

nice (name derived from being “nice” to other system users by running large programs at lower priority) executes command at a non-default CPU scheduling priority.  Command-line arguments are as follows:

priority_change Specifies the difference between the system nice value (relative priority) of the current (or parent) process and the actual system nice value at which command is to be run.  An unsigned value increases the system nice value for command, causing it to run at lower priority; a negative value requires super-user privileges, and assigns a lower (higher priority) system nice value to command.

If the value of priority_change would result in a system nice value outside the range 0 through 39, the corresponding limit value of 0 or 39 is used instead. 

Note that a positive priority_change (lower priority) has a single - option character before the numeric value; a negative (higher priority) priority_change has two; the option character followed by the minus sign: --.  If priority_change is not specified, the default value of 10 (lower priority) is used. 

command Program, HP-UX command, user shell script, etc.  to be executed at non-default priority.  command can be run as a foreground or background process. 

If command is run as a background process, any nice priority_change made by the shell (ksh executes all background processes via nice -4) is in addition to that specified in the nice command line. 

command_args Any arguments recognized by command.

Process Priorities

All processes have an associated system nice value which is used to compute the instantaneous-priority of the process when it is scheduled to run.  Normally, all processes inherit the system nice value of their parent process when they are spawned.  The shell (sh, csh, ksh, etc.)  can create a child process with a different priority than the current shell process by spawning the child process via the nice command.  If the priority_change value is unsigned (positive), the child process is nicer (lower in priority) relative to the parent.  If the priority_change value is negative, the child process runs at a higher priority with a greater share of available system resources.  To spawn a higher priority child process, the parent process must be owned by a user who has the necessary privileges. 

At boot-up, the system starts the init process at a system nice value of 20 (system default).  On most systems, all processes (down to the login shells) inherit this priority.  Starting from their individual login shell processes, users can alter the system nice value of descendent processes to as much as 39, or, with appropriate privileges, as little as 0.  A system nice value of 0 establishes an extremely high priority, whereas a value of 39 indicates a very low priority. 

Ordinary users can only increase the system nice value of any child process relative to the current process; i.e., priority_change must be a positive (unsigned) value, resulting in a lower priority.  To start a child process at a lower system nice value (higher priority) than the current process, the user must have the appropriate privileges listed above, regardless of the relative nice-priority value desired. 

For example, using the command

nice ksh

from a login shell whose current nice value is 20 spawns a sub-shell with a system nice value of 30.  Attempting to use

nice --2 ksh

to spawn another subshell whose system nice value would be 28, is rejected (unless the user has the necessary privileges), even though the resulting system nice value would be less than the priority of the original login shell process. 

The system nice value for current processes is listed under the NI column produced by the ps -l command (see ps(1)).

Background Processes

Foreground processes are run at same system nice value as the parent shell.  Background processes spawned by ksh run at the equivalent of a nice -4 by default.  If a background process is started via nice from ksh, any priority_change specified in the nice command is added to default nice -4.  Thus the command nice 12 command & runs at a system nice value of 36 if executed from ksh. 

EXTERNAL INFLUENCES

International Code Set Support

Single- and multi-byte character code sets are supported. 

RETURN VALUE

nice returns the value returned by command.

EXAMPLES

The following examples assume the current process is running with a system nice value of 20 and nice is executed from the Korn shell (see ksh(1)).

Run a program named prog in the current directory at the default priority_change of 10 (system nice value of 30):

nice ./prog prog_args

From Korn shell (see ksh(1)), run the same program in the background using a system nice value of 36 (priority_change=12):

nice -12 ./prog prog_args &

As a user with appropriate privileges, run prog as a foreground process with a system nice value of 6:

nice --14 ./prog prog_args

WARNINGS

csh has a built-in nice command with syntax that is different from the syntax of the standard system nice command, and which behaves as follows:

nice +priority_change
Increases the system nice value for the current shell by priority_change.

nice -priority_change
Decreases the system nice value for the current shell by priority_change.

nice Sets the system nice value for the current shell to 39, making it very difficult to get any response from a busy system. 

nice command
Executes command in a sub-shell with a default priority_change of 4 from the system nice value for the current shell process. 

nice priority_change command ... 
Executes command in a sub-shell at the specified priority_change from the system nice value for the current shell process. 

SEE ALSO

nohup(1), renice(1), nice(2). 

STANDARDS CONFORMANCE

nice: SVID2

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026