Nice (Unix)
Template:Short description Template:Redirect Template:Refimprove Template:Lowercase {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other
nice
is a program found on Unix and Unix-like operating systems such as Linux. It directly maps to a kernel call of the same name. nice
is used to invoke a utility or shell script with a particular CPU priority, thus giving the process more or less CPU time than other processes. A niceness of -20 is the lowest niceness, or highest priority. The default niceness for processes is inherited from its parent process and is usually 0.
Systems have diverged on what priority is the lowest. Linux systems document a niceness of 19 as the lowest priority,<ref name="linuxrenice">Template:Man</ref> BSD systems document 20 as the lowest priority.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> In both cases, the "lowest" priority is documented as running only when nothing else wants to.
EtymologyEdit
Niceness value is a number attached to processes in *nix systems, that is used along with other data (such as the amount of I/O done by each process) by the kernel process scheduler to calculate a process' 'true priority'Template:Emdashwhich is used to decide how much CPU time is allocated to it.
The program's name, nice, is an allusion to its task of modifying a process' niceness value.
The term niceness itself originates from the idea that a process with a higher niceness value is nicer to other processes in the system and to users by virtue of demanding less CPU powerTemplate:Emdashfreeing up processing time and power for the more demanding programs, who would in this case be less nice to the system from a CPU usage perspective.<ref>Jerry Peek, Shelley Powers, Tim O'Reilly and Mike Loukides (2002). Unix Power Tools. O'Reilly, p. 507.</ref>
Use and effectEdit
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 (root) may set the niceness to a lower value (i.e. a higher priority). On Linux it is possible to change /etc/security/limits.conf
to allow other users or groups to set low nice values.<ref>Template:Man</ref>
If a user wanted to compress a large file without slowing down other processes, they might run the following: <syntaxhighlight lang="console"> $ nice -n 19 tar cvzf archive.tgz largefile </syntaxhighlight>
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.<ref>Template:Cite book</ref> On the BSD 4.x scheduler, on the other hand, the ratio in the same example is about ten to one.Template:Citation needed
Similar commandsEdit
The related renice
program can be used to change the priority of a process that is already running.<ref name="linuxrenice"/>
Linux also has an ionice
program, which affects scheduling of I/O rather than CPU time.<ref>Template:Man</ref>
See alsoEdit
- kill
- ps
- top
- ionice from util-linux (see manual for disk storage I/O priorities)