nice can be used to manipulate process CPU scheduling priorities. The command assigns a "niceness" value from -20 (most important) to +19 (least important) to the process. Root can assign any value, other users only positive ones (minor importance). The default value is 0.
nice -n <niceness> <command>
To set the priority of an apt-get command to the least value, you can use the command
sudo nice -n 19 apt-get upgrade
To set the priority of an already running process, the command
renice can be used:
renice -n <niceness> -p <pid>
Edit: Thanks to @David for mentioning the
ionice command, which lets you manipulate disk I/O priority. It can put a process into three different classes:
- Idle only gives the process disk time, if no other process claims it at the moment.
- Best-effort (default class). This allows you to assign priorities from 0 to 7, where 0 is most important and 7 least. You may try assigning
-n 7 as the priority level.
- Realtime processes are handled before everything else, suspending disk I/O for other processes, as soon as they require it for themselves. Use with care!
IOnice combines the syntax of nice and renice:
ionice [-c class] [-n level] command #To start a new process
ionice [-c class] [-n level] -p pid #To change a running process
Both commands can be combined, e.g.
sudo ionice -n 7 nice -n 19 apt-get upgrade #Omitting the -c switch will assign Best-effort
sudo nice -n 19 ionice -n 7 apt-get upgrade
nice -n 19 ionice -n 7 sudo apt-get upgrade