CPU Usage | Process   «Prev  Next»
Lesson 5Changing dispatching priorities
ObjectiveRun the nice command to change CPU dispatching priorities.

Changing dispatching priorities

Overview of nice

Dispatching priorities are controlled with the UNIX nice command. The nice command lets you run a command at a lower than normal priority.

Displaying nice values

The nice values for tasks can be seen by using the –l option with the UNIX ps command.
ps – elf|sort + [column number] | [head] 0

When you enter ps –elf, the nice value will be an eight column table. The result displays the top priority tasks on the database server, those with the smallest nice values. Nice values will range from 0, for top priority, to 39 for the lowest priority. View the code below to see the critical parts of this data.

The root processes have the highest priority
  1. The root processes have the highest priority (8) while the Oracle database tasks all have a priority of 20.
  2. This Oracle task has the lowest dispatching priority of 22. It originally had a nice value of 20. The UNIX OS detected that it was a long-running job and automatically lowered the dispatching priority for this task, so that other online tasks would execute faster.
  3. The command parameter is the name of any executable file on the system.
  4. If you do not specify an increment value, the nice command defaults to an increment of 10.
View Dispatching Priorities
You must have root user authority to run a command at a higher priority. You can, however, lower the values of Oracle tasks with nice without root user authority.

Using nice

There may be time when you want to lower the default dispatching priority. For example, a long-running batch task, one that runs more than 30 minutes, can be given a lower priority so that online transactions will get faster service.
The following command submits myprog.ksh in the background with a high nice value, thereby making it run more slowly and consume CPU resources only when other tasks do not require CPU.

nohup nice –n 25 myprog.ksh &
The nice command only works at the time that a task is started, and you cannot dynamically change the nice value.

Using renice

If you want to change the priority of a task that is already executing, you can use the renice command.
If you have root user authority, you can alter the priority of any process and set the priority to any value in the range -20 to 20. The specified increment changes the priority of a process in the following ways:
Increment values
  1. 1 to 20--Runs the specified processes slower than the base priority
  2. 0--Sets the priority of the specified processes to the base scheduling
  3. -20 to –1--Runs the specified processes quicker than the base priority

For example, assume that Oracle process ID (PIDs) 445 and 6678 are consuming too many resources:

Using the renice command
Using the renice command

Now, take another look at the dispatching priority:
Results of using the renice command
Results of using the renice command

We now see that it has dropped to priority 25, meaning that it will execute more slowly than other Oracle tasks that have a nice value of 20. The next lesson wraps up this module.