I am using bzip2 to compress a file,the process takes more that 100% cpu.Is there any way to run bzip2 with minimum CPU precentage.
Recommended: using priorities
In addition to @EEAA answer, if you want to give the maximum of low priority to the bzip process, so that when other processes are impacted a minimum, you should use
ionice in addition. Note, that
ionice is only useful when using the
CFQ IO scheduler (the default on the Kernel, but this could have been tweak by your installation).
ionice will have no effect AFAIK if you are using the
noop IO scheduler.
To verify which IO scheduler you are using:
<DEVICE> is your hard disk device, e.g.
ionice, you want to set the lowest IO priority which is the class 3. And you can combine it with
$ nice -n 19 ionice -c3 bzip2 <file>
As Tom and EEAA explained, this is good enough. The kernel will make sure that bzip can run as fast as possible when no other process needs CPU or IO. But it will give the priority to other processes if they need it. This is the recommended choice.
Alternative: cpulimit - limits the CPU usage in pourcentage
Now you can still use a "CPU limitation" on bzip. That would not be my choice, but if you want to experiment or like it better, you should use
cpulimit. However, it is not often packaged or in a default Linux installation. So you will have to install it. NixCraft has a good document how to install and use
The official web site is: http://cpulimit.sourceforge.net/