Every process in the system is running with defined priorities (also called “nice value”). This value may vary from -20 to +20. The maximum priority value for processes is -20. If it is not defined, every process will run with priority 0 by default (the “base” scheduling priority). Processes with maximum priority (any negative value up to -20) use more system resources than others. Processes with minimal priority (+20) will work when the system is not used by other tasks. Users other than the super-user may only lower the priority of processes they own within a range of 0 to 20. The super-user (root) may set the priority of any process to any value.
If one or more processes use too much system resource, you can change their priorities instead of killing them. For such tasks the renice command can be used. Its syntax is as follows:
renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...] |
where priority is the value of the priority, pid (use option -p for multiple processes) is the process ID, pgrp (introduced by -g if various) is the process group ID, and user (-u for more than one) is the username of the process owner.
Let's suppose you have run a process with PID 785, which makes a long scientific operation, and while it is working you want to play a game. Then you type:
$ renice +15 785 |
In this case your process will possibly work a little bit longer. However it will not prevent other important processes using more CPU time.
If you are the system administrator and you see that some user is running too many processes and they use too many system resources, you can change that user's process priority with a single command:
# renice +20 -u peter |
After this, all of peter's processes will have the lowest priority and will not obstruct any other user's processes.
Now that you know that you can change the priority of processes, you may wish to run a command with a defined priority. For this, use the nice command.
It must be typed before the command which you want to run. By default nice sets a priority of 10. Range goes from -20 (highest priority) to 19 (lowest). Option -n is used to set priority value.
For example, you want to create an iso image of a Mandrake Linux installation CD-ROM:
$ dd if=/dev/cdrom of=~/mdk1.iso |
However on some systems with a usual IDE CD-ROM, the process of large volume information copying can use too many system resources. In order for this process to not prevent others from working, we can start the copying process with a lowered priority by using this command:
$ nice -n 19 dd if=/dev/cdrom of=~/mdk1.iso |
and continue our common work.
To change a process' priority you also can use the above described top utility. Use command r within top's interface to change the priority of selected process.