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. Only the superuser may set the niceness to a lower 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 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. 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: / = 0.25. On the BSD 4.x scheduler, on the other hand, the ratio in the same example is about ten to one.
Similar commands
The related renice program can be used to change the priority of a process that is already running. Linux also has an ionice program, which affects scheduling of I/O rather than CPU time.
Etymology
The name "nice" comes from the fact that the program's purpose is to modify a process niceness value. The true priority, used to decide how much CPU time to concede to each process, is calculated by the kernel process scheduler from a combination of the different processes' niceness values and other data, such as the amount of I/O done by each process. The name "niceness" originates from the idea that a process with a higher niceness value is "nicer" to other processes in the system:
This is why the nice number is usually called niceness: a job with a high niceness is very kind to the users of your system, while a job with little niceness utilises more of the CPU. The term "niceness" could be considered awkward. Unfortunately, it's the only term that is both accurate and avoids horrible circumlocutions.