Changing process priorities: nice and renice

From CTSWiki

Jump to: navigation, search
Image:WustlLogo.jpg

Contents

Changing process priorities under Unix

If you run CPU-intensive processes, you should familiarize yourself with the nice and, renice, and pbind commands.

Every process has a nice value in the range from 0 to 39, with 39 being the nicest. Nicer processes tend to yield the CPU to less nice processes. By default, user processes start with a nice value of 20. You can see the current nice value of a process in the NI column of a ps listing.

The nice command starts a process with a non-default nice value. There are two versions of the nice command: one built in to the csh, and one in /usr/bin/nice.

If You Use the csh (or tcsh, bash)

The syntax is:

  • nice +n command
  • nice +19 TRAINREC ... # nice value will be 39

n is 20 less than the nice value to be used to run command.

If You Use Some Other Shell

Using another shell will have you will using /usr/bin/nice. This has the syntax:

  • nice -n command

Again, n is 20 less than the nice value to be used to run command.

The Renice Command

Located in /usr/bin/renice (/usr/ucb/renice for Solaris), the renice command changes the nice value of a process already running. It's syntax is:

  • renice n pid
  • renice 19 8209 # set nice value of process 8209 to 39

n is 20 less than the new nice value. pid is the process ID.

Users can only affect the nice value of processes which they own. They cannot start processes with nice values less than 20, nor can they lower the nice values of their processes after they've raised them.

Personal tools