Running a command with the nice command

Any user can run a command at a less-favorable-than-normal priority by using the nice command.

Only the root user can use the nice command to run commands at a more-favorable-than-normal priority. In this case, the nice command values range between -20 and 19.

With the nice command, the user specifies a value to be added to or subtracted from the standard nice value. The modified nice value is used for the process that runs the specified command. The priority of the process is still non-fixed; that is, the priority value is still recalculated periodically based on the CPU usage, nice value, and minimum user-process-priority value.

The standard nice value of a foreground process is 20 (24 for a ksh background process). The following command would cause the vmstat command to be run in the foreground with a nice value of 25 (instead of the standard 20), resulting in a less favorable priority.
# nice -n 5 vmstat 10 3 > vmstat.out
If you use the root login, the vmstat command can be run at a more favorable priority with the following:
# nice -n -5 vmstat 10 3 > vmstat.out

If you were not using root login and issued the preceding example nice command, the vmstat command would still be run but at the standard nice value of 20, and the nice command would not issue any error message.