manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

22.3 nice: Run a command with modified niceness

nice prints or modifies a process's niceness, a parameter that affects whether the process is scheduled favorably. Synopsis:

nice [option]… [command [arg]…]

If no arguments are given, nice prints the current niceness. Otherwise, nice runs the given command with its niceness adjusted. By default, its niceness is incremented by 10.

Nicenesses range at least from -20 (resulting in the most favorable scheduling) through 19 (the least favorable). Some systems may have a wider range of nicenesses; conversely, other systems may enforce more restrictive limits. An attempt to set the niceness outside the supported range is treated as an attempt to use the minimum or maximum supported value.

A niceness should not be confused with a scheduling priority, which lets applications determine the order in which threads are scheduled to run. Unlike a priority, a niceness is merely advice to the scheduler, which the scheduler is free to ignore. Also, as a point of terminology, POSIX defines the behavior of nice in terms of a nice value, which is the nonnegative difference between a niceness and the minimum niceness. Though nice conforms to POSIX, its documentation and diagnostics use the term “niceness” for compatibility with historical practice.

command must not be a special built-in utility (see section Special built-in utilities).

Because many shells have a built-in nice command, using an unadorned nice in a script or interactively may get you different functionality than that described here.

The program accepts the following option. Also see Common options. Options must precede operands.

-n adjustment

Add adjustment instead of 10 to the command's niceness. If adjustment is negative and you lack appropriate privileges, nice issues a warning but otherwise acts as if you specified a zero adjustment.

For compatibility nice also supports an obsolete option syntax ‘-adjustment’. New scripts should use ‘-n adjustment’ instead.

Exit status:

0   if no command is specified and the niceness is output
1   if nice itself fails
126 if command is found but cannot be invoked
127 if command cannot be found
the exit status of command otherwise

It is sometimes useful to run a non-interactive program with reduced niceness.

$ nice factor 4611686018427387903

Since nice prints the current niceness, you can invoke it through itself to demonstrate how it works.

The default behavior is to increase the niceness by ‘10’:

$ nice
$ nice nice
$ nice -n 10 nice

The adjustment is relative to the current niceness. In the next example, the first nice invocation runs the second one with niceness 10, and it in turn runs the final one with a niceness that is 3 more:

$ nice nice -n 3 nice

Specifying a niceness larger than the supported range is the same as specifying the maximum supported value:

$ nice -n 10000000000 nice

Only a privileged user may run a process with lower niceness:

$ nice -n -1 nice
nice: cannot set niceness: Permission denied
$ sudo nice -n -1 nice

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© 2000-2021
Individual documents may contain additional copyright information.