SET PRIORITIES WITH NICE

With a multitasking operating system like Linux, multiple processes running at the same time often fight for the CPU cycles. Knowing how to handle those processes and make some behave better than they typically do is important for all Linux users to understand.

Each process has a niceness value assigned to it, and this value is what the kernel uses to determine relationships between processes that want to use the CPU. The higher the nice value, the lower the priority of the process and the less CPU cycles it will draw. The range of a process' nice value can be from -20 to +19.

More often than not, a program inherits its nice value from its parent process. This prevents low priority processes from spawning high priority children.

Of course, this wouldn't be Linux if you weren't able to modify the niceness of a process. You can use the nice command to set a nicenesslevel at the beginning of a process, and you can use the renice command to change the niceness of a process that's already running. Here are some examples:

$ nice -n 10 /usr/bin/someprogram

$ renice -5 12398

$ renice 10 -u joe

The first will lower someprogram's niceness level by 10. The second will set the nice value of process 12398 to -5, and the last will set all of the user joe's processes to 10.