Sometimes it happens that you want to laubnch some heavy operations in the background without slowing down other software. For example:
In this situation nice and ionice can be used.
Launching a program
- nice allows you to reduce the priority of a process on the CPU
- ionice reduces the priority of a process on disk access.
ionice -c3 nice -n15 myprogram
The program launched will use CPU and disk resources only when no other program is making use of it.
In a shell script
Place at the beginning of your shell script:
ionice -c3 -p$$
renice +15 -p $$
The shell will have its priority reduced (and this will be applicable for all programs launched within this shell).
This is useful in the scripts launched in /etc/cron.
You can add these lines to your script: /etc/cron.daily/slocate
nice and renice can be used by everyone.
ionice with -c3 can be used only by root.