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

May 2017





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


Published by netty5. Latest update on December 13, 2009 at 02:58 AM by jak58.
This document, titled "Launching a program in low CPU and disk I/O priority," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).