Changing a process' priority using ``nice'' or ``renice''

Every process running on a Unix computer is assigned a priority value. When many programs are running simultaneously on the computer, those programs with higher priority are given bigger chunks of CPU time, while those with lower priority are given less. On the other hand, when nobody is logged on and there are relatively few processes, then even a program with low a priority value can get plenty of CPU time, up to 99% of it.

As part of normal lab courtesy, folks logged on at the console and doing actual "face time" with the computer should get priority for jobs they are running. Therefore, if you are running big numbercrunching jobs remotely (from another location) or in the background (i.e., without remaining logged on anywhere), be sure to run them with a lower priority.

To do that, prefix your Unix command with the word ``nice -n 19''. This will run the job at an acceptable priority, taking up to 99% of the computer's CPU time if no other significant jobs are running, but dropping down to less while somebody else uses the computer. For example,

simpson>  nice  -n 19  ./mybigjob  >  ./results.dat  &
If your job is already running and you forgot to make it nice, you can do so retroactively using the command renice, for which you need the program's process ID number (PID), which is listed by the command /bin/ps -elf. For example, to retroactively make nice your program "mybigjob", find its PID and then renice:
simpson>  /bin/ps -elf | grep mybigjob
 F S   UID    PID  PPID  C PRI NI  ADDR   SZ  WCHAN   STIME  TTY     TIME CMD
 8 S  jsmith 12429 12425 0  81 20    ?    245     ? 09:15:18 pts/10  8:47 mybigjob > .results.dat
simpson>  renice  -n 19  12429       # increase to max niceness

 


manual page for ``nice''

go to
man page for renice

     nice - invoke a command with an altered scheduling priority

SYNOPSIS
   /usr/bin/nice [ -increment | -n increment ] command [ argument ... ]
  
        csh Builtin:
   nice [ -increment | +increment ]  [ command ]

DESCRIPTION
     The nice utility invokes command, requesting that it be  run
     with a different system scheduling priority. The priocntl(1)
     command is a more general interface to scheduler functions.

     The invoking process (generally the user's shell) must be in
     a scheduling class that supports nice.

     If the C shell (see csh(1)) is used, the full  path  of  the
     command  must be specified; otherwise, the csh built-in ver-
     sion of nice will be invoked. See csh Builtin below.

  /usr/bin/nice
     If nice  executes  commands  with  arguments,  it  uses  the
     default shell /usr/bin/sh (see sh(1)).

  /usr/xpg4/bin/nice
     If  nice  executes  commands   with   arguments,   it   uses
     /usr/xpg4/bin/sh,  which  is equivalent to /usr/bin/ksh (see
     ksh(1)).

  csh Builtin
     nice is also a csh built-in command with behavior  different
     from the utility versions.  See csh(1) for description.

OPTIONS
     The following options are supported:

     -increment | -n increment
           increment must be in the range 1-19; if not specified,
           an  increment  of  10 is assumed. An increment greater
           than 19 is equivalent to 19.

           The super-user may run commands with  priority  higher
           than normal by using a negative increment such as -10.
           A negative increment assigned by an unprivileged  user
           is ignored.

OPERANDS
     The following operands are supported:

     command
           The name of a command that is to be invoked.  If  com-
           mand  names any of the special built-in utilities (see
           shell_builtins(1)), the results are undefined.

     argument
           Any string to be supplied as an argument when invoking
           command.

 


manual page for ``renice''

go to
man page for nice

     renice - alter priority of running processes

SYNOPSIS
     renice [ -n increment ]  [ -g | -p  | -u ]  ID ...

     renice priority  [ -p ]  pid ...  [ -g gid ... ]   [  -p pid
     ... ]  [ -u user ... ]

     renice priority  -g gid ...  [ -g gid ... ]  [ -p pid ...  ]
     [ -u user ... ]

     renice priority  -u user ...  [ -g gid ... ]  [ -p pid ... ]
     [ -u user ... ]

DESCRIPTION
     The renice command alters the scheduling priority of one  or
     more  running  processes.  By  default,  the processes to be
     affected are specified by their process IDs.

     If the first operand is a number within the valid  range  of
     priorities  (-20 to 20), renice will treat it as a  priority
     (as in all but the first synopsis form); otherwise,   renice
     will treat  it as an  ID (as in the first synopsis form).

  Altering Process Priority
     Users other than the privileged  user  may  only  alter  the
     priority  of  processes they own, and can only monotonically
     increase their "nice value" within the range 0 to  19.  This
     prevents  overriding  administrative  fiats.  The privileged
     user may alter the priority  of  any  process  and  set  the
     priority to any value in the range -20 to 19. Useful priori-
     ties are: 19 (the affected  processes  will  run  only  when
     nothing else in the system wants to), 0 (the "base" schedul-
     ing priority) and any negative value (to make things go very
     fast).  20  is an acceptable nice value, but will be rounded
     down to  19.

OPTIONS
     renice supports the following option features:

        o  The first operand, priority, must precede the  options
           and can have the appearance of a multi-digit option.

        o  The -g, -p and  -u  options  can  each  take  multiple
           option-arguments.

        o  The pid option-argument can be  used  without  its  -p
           option.

     The following options are supported:

     -g    Interpret all operands or just the  gid  arguments  as
           unsigned decimal integer process group IDs.

     -nincrement
           Specify how the  system  scheduling  priority  of  the
           specified process or processes is to be adjusted.  The
           increment option-argument is a  positive  or  negative
           decimal integer that will be used to modify the system
           scheduling  priority  of  the  specified  process   or
           processes.  Positive  increment  values  cause a lower
           system scheduling priority.  Negative increment values
           may  require  appropriate  privileges and will cause a
           higher system scheduling priority.

     -p    Interpret all operands or just the  pid  arguments  as
           unsigned  decimal  integer process IDs.  The -p option
           is the default if no options are specified.

     -u    Interpret all operands or just the  user  argument  as
           users.  If a user exists with a user name equal to the
           operand, then the user ID of that user will be used in
           further   processing.   Otherwise,   if   the  operand
           represents an unsigned decimal  integer,  it  will  be
           used as the numeric user ID of the user.

OPERANDS
     The following operands are supported:

     ID    A process ID, process group ID or user  name/user  ID,
           depending on the option selected.

     priority
           The value specified is  taken  as  the  actual  system
           scheduling  priority,  rather  than as an increment to
           the existing system scheduling priority. Specifying  a
           scheduling  priority  higher than that of the existing
           process may require appropriate privileges.

EXAMPLES
     Example 1: Examples of renice.

     Adjust the system scheduling priority so  that  process  IDs
     987 and 32 would have a lower scheduling priority:

     example% renice -n 5 -p 987 32

     Adjust the system scheduling priority so that group IDs  324
     and  76 would have a higher scheduling priority, if the user
     has the appropriate privileges to do so:

     example% renice -n -4 -g 324 76

     Adjust the system scheduling priority so that  numeric  user
     ID 8 and user sas would have a lower scheduling priority:

     example% renice -n 4 -u 8 sas

     Users  other  than  the  privileged  user  cannot   increase
     scheduling  priorities  of their own processes, even if they
     were the ones that decreased the  priorities  in  the  first
     place.