Using nice to control CPU usage

Managing tasks that use up a lot of CPU time can be quite a task and if you're working in a shared environment where you don't want to be antisocial and use all the available resources, it can be necessary to manage the tasks you are running to ensure you are being nice.

And nice is exactly the command you need to use for this purpose. What it allows you to do is force a command to run with a different priority level. The levels range from -20 (top priority) down to 19 (lowest priority).

It's pretty simple to use, simply prefix the desired commands you want to run with the following:

$ nice -n prioritylevel commandtorun

For example, I could run a backup with tar with lowest priority:

$ nice -n 19 tar -cjvf /backup.tar.bz2 /folder/to/backup

nice is available on literally all Linux systems and almost all other Unix-like operating systems too. Some versions may differ very slightly, but the basic functionality will remain the same.

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Using nice to control CPU usage

Home » Articles » Using nice to control CPU usage