Set Process Priority: Nice and renice
Each process running in the system has a priority (also known as "nice value") ranging from-20 (highest priority) to 19 (lowest priority ). By default, the priority of a process is 0 ("basic" scheduling priority ). Processes with a higher priority (Nice value is relatively small, and the lowest is-20) processes with a lower priority (until 19) will be scheduled to run more frequently, therefore, more process cycles are available. Generally, users can only reduce the priority of their own processes, and the range is between 0 and 19. Superuser (RootCan set the priority of any process to any value.
Renice
If a process or process consumes too much system resources, you can change their priority in addition to terminating them. To do this, useReniceCommand. Its syntax is:
Renice priority [[-p] PID...] [[-G] pgrp...] [[-u] username...] |
Where,PriorityIndicates the priority value;PID(For multiple processes, use-P(Optional) indicates the process ID;Pgrp(Use-G) Indicates the process group ID.User(If there are more than one, use-U) Indicates the User Name of the process owner.
Assume that you have run a long time science computing process (with a PID of 785), but you want to play a game and release some system resources. You can:
In this way, your process may take longer to complete, but it will not take the CPU time slice from other processes.
If you are a system administrator and you find that some users have executed too many processes and consumed too much system resources, you only need to enter one command to change the priority of these user processes:
In this way, all li_si processes have the lowest priority, so they will not hinder other users' processes.
Nice
Now that you know that you can change the priority of a process, you may need to execute commands Based on the specified priority. To do this, useNiceCommand.
In this case, you need to use the command you want to runNice. Another parameter-NCan be used to set priority. By defaultNiceSet the priority to 10.
For example, if you want to create an ISO image for the mandrakelinux installation CD-ROM:
$ dd if=/dev/cdrom of=~/mdk1.iso |
On some systems that assemble standard ide CD-ROM, copying large amounts of information consumes too much system resources. To prevent the replication operation from interfering with other processes, run the following command to start the process at a lower priority:
$ nice -n 19 dd if=/dev/cdrom of=~/mdk1.iso |
Then you can continue to work.