Nice (Unix) - Use and Effect

Use and Effect

nice becomes useful when several processes are demanding more resources than the CPU can provide. In this state, a higher priority process will get a larger chunk of the CPU time than a lower priority process. If the CPU can deliver more resources than the processes are requesting, then even the lowest priority process can get up to 99% of the CPU. Only the superuser (root) may set the niceness to a smaller (higher priority) value. On Linux it is possible to change /etc/security/limits.conf to allow other users or groups to set low nice values.

If a user wanted to compress a large file, but not slow down other processes, they might run the following:

$ nice -n 19 tar cvzf archive.tgz largefile

The related renice program can be used to change the priority of a process that is already running.

The exact mathematical effect of setting a particular niceness value for a process depends on the details of how the scheduler is designed on that implementation of Unix. A particular operating system's scheduler will also have various heuristics built into it, e.g. to favor processes that are mostly I/O-bound over processes that are CPU-bound. As a simple example, when two otherwise identical CPU-bound processes are running simultaneously on a single-CPU Linux system, each one's share of the CPU time will be proportional to 20−p, where p is the process' priority. Thus a process run with nice +15 will receive 25% of the CPU time allocated to a normal-priority process: (20−15)/(20−0) = 0.25. On the BSD 4.x scheduler, on the other hand, the ratio in the same example is about ten to one.

Linux also has an ionice program, which affects scheduling of I/O rather than CPU time.

Read more about this topic:  Nice (Unix)

Famous quotes containing the word effect:

    Nothing could his enemies do but it rebounded to his infinite advantage,—that is, to the advantage of his cause.... No theatrical manager could have arranged things so wisely to give effect to his behavior and words. And who, think you, was the manager? Who placed the slave-woman and her child, whom he stooped to kiss for a symbol, between his prison and the gallows?
    Henry David Thoreau (1817–1862)