103.6 Modify Process Execution Priorities
Candidates should be able to manage process execution priorities.
Key Knowledge Areas
- Know the default priority of a job that is created.
- Run a program with higher or lower priority than the default..
- Change the priority of a running process.
When a process is started by a user it has a default priority, or nice number of 0. Nice numbers (NI) alter the CPU priority and are used to balance the CPU load in a multiuser environment. Nice numbers range from 19 [lowest] to -20 [highest].
Only root can decrease the nice number of a process. Since all processes start with a default nice number of zero as a consequence negative nice numbers can only be set by root!
To modify a process' priority that is already running use renice. To set a process' priority use nice.
# nice –<NI> <process> # renice <+/-NI> -p <PID>
Notice that renice works with PIDs and handles lists of processes at a time. A useful option to renice is the -u option which affects all processes run by a user.
Set nice number 1 for processes 234 and 765:
# renice +1 -p 234 765
Set nice number -5 for xclock:
# nice --5 xclock
Continuously updating process information
The top utility will update information on processes at an adjustable rate. While top is running you can type h for a list of commands. The space bar will update information instantly. You can also use top to change a process' priority as we shall see in the next section. Top provides a convenient summary of number of processes, users, length of time the machine has been up and the load average for the past 5, 10 and 15 minutes. You can also obtain this information once off with the uptime command. Below is an example of the output you can expect from running this command.
13:21:48 up 5:54, 1 user, load average: 0.92, 0.70, 0.66
Here 13:21 is the current time, 5:54 is the length of time the machine has been up, 1 user is logged in and the load average for the past 5,10 and 15 minutes is 0.82, 0.70 and 0.66.
Used files, terms and utilities: