Monday, August 23, 2010

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

http://en.kioskea.net/faq/864-launching-a-program-in-low-cpu-and-disk-i-o-priority

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

No comments: