Skip to content

Nice linux command, nice baby

January 11, 2010

Most Linux users know of the nice command but few actually use it. Nice is one of those commands that sound really good, but you can never think of a reason to use. Occasionally though, it can be incredibly useful. Nice can change the priority of a running process, giving it a greater or smaller share of the processor. Usually this is handled by the Linux scheduler. The scheduler guarantees that processes with a higher priority (like those that involve user input) get their share of the resources. This should ensure that even when your system is at 100% CPU, you will still be able to move the windows and click on the mouse.

The scheduler doesn’t always work smoothly, however; certain tasks can take over your computer. This could be a wayward find command that’s triggered by a distro’s housekeeping scripts; or encoding a group of video files that makes your computer grind to a halt.

You’d typically hunt these processes out with the top comand before killing them. Nice presents another, more subtle and more useful option. It reduces the offending task’s priority so that your system remains usable while still serving the offending process. Running a command with a different priority is as easy as entering

nice --10 updatedb

This runs the updatedb with a reduced priority of -10. If you run top you can see the nice value under the column labelled ‘NI’.

If you wish to reduce the priority of a program that’s already running, you need to use the renice command with the process ID:

# renice -10 -p 1708217082: old
priority 0, new priority -10

This will also reduce the process’s priority by 10, and depending on the nice value of the other processes, will lessen the amount of CPU time it will share with the other tasks.


From → linux

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: