Bash – Alternating a long running task to pause/run to reduce cpu

bashlinuxprocess

I have large file I need to mv and even with nice -n19 it seems to affect the server performance.

I think an option would be to run the process in "chunks" whereby I run the command for a few seconds, then sleep for a few, then resume the process.

Is there a way to do this from the command line or a better alternative ? Currently I do a Ctrl Z and fg manually.

Best Answer

Your performance impact is likely caused by a I/O bottleneck because mv does not normally require a lot of CPU cycles (unless encryption/decryption is involved). nice changes the scheduling priority of the task in the task list, which get to run on the CPU.

Therefore, instead of nice, try (for kernel > 2.6.25)

ionice -c3 mv <src> <dest>

From ionice -h

 ionice [options] <command>
   -c, --class <class>    name or number of scheduling class,
                      0: none, 1: realtime, 2: best-effort, 3: idle

From man ionice

 Idle   A program running with idle I/O priority will only get disk time 
        when no other program has asked for disk I/O for a defined grace 
        period.  The impact of an idle I/O process on normal system activity
        should be zero.
Related Question