Launching a program in low CPU and disk I/O priority

December 2016





Intro


Sometimes it happens that you want to laubnch some heavy operations in the background without slowing down other software. For example:
Copying files
Backups
Indexing (updatedb).

In this situation nice and ionice can be used.
  • nice allows you to reduce the priority of a process on the CPU
  • ionice reduces the priority of a process on disk access.


Launching a program

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:

#!/bin/sh
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

Notes


nice and renice can be used by everyone.
ionice with -c3 can be used only by root.

Related :

This document entitled « Launching a program in low CPU and disk I/O priority » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.