Nice (Unix)

Computer utility for Unix-like operating systems

"Renice" redirects here. For the Polish village, see Renice, Poland.

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Nice" Unix – news · newspapers · books · scholar · JSTOR (November 2010) (Learn how and when to remove this message)

|

nice

Developer(s)| AT&T Bell Laboratories
Initial release| November 1973; 51 years ago (1973-11)
Operating system| Unix and Unix-like
Platform| Cross-platform
Type| Command
License| coreutils: GNU GPL v3 4.4BSD: BSD License

`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,[1] BSD systems document 20 as the lowest priority.[2] In both cases, the "lowest" priority is documented as running only when nothing else wants to.

## Etymology

[edit]

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'—which 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 power—freeing 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.[3]

## Use and effect

[edit]

`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.[4]

If a user wanted to compress a large file without slowing 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 (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.[5] On the BSD 4.x scheduler, on the other hand, the ratio in the same example is about ten to one.[citation needed]

## Similar commands

[edit]

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

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

## See also

[edit]

* kill
* ps
* top
* ionice from util-linux (see manual for disk storage I/O priorities)

## References

[edit]

1. ^ a b `renice(1)` – Linux General Commands Manual
2. ^ "renice(8) - NetBSD Man Pages". NetBSD. October 22, 2020. Retrieved April 18, 2023.
3. ^ Jerry Peek, Shelley Powers, Tim O'Reilly and Mike Loukides (2002). Unix Power Tools. O'Reilly, p. 507.
4. ^ `limits.conf(5)` – Linux File Formats Manual
5. ^ Silberschatz, Abraham; Galvin, Peter B.; Gagne, Greg (2013). Operating system concepts (ninth ed.). Hoboken, N.J: Wiley. p. 294\. ISBN 978-1-118-06333-0.
6. ^ `ionice(1)` – Linux General Commands Manual

## External links

[edit]

The Wikibook Guide to Unix has a page on the topic of: Commands

* `nice`: invoke a utility with an altered nice value – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group

* v
* t
* e

Unix command-line interface programs and shell builtins

File system|

* cat
* chattr
* chmod
* chown
* chgrp
* cksum
* cmp
* cp
* dd
* du
* df
* file
* fuser
* ln
* ls
* mkdir
* mv
* pax
* pwd
* rm
* rmdir
* split
* tee
* touch
* type
* umask

Processes|

* at
* bg
* crontab
* fg
* kill
* nice
* ps
* time

User environment|

* env
* exit
* logname
* mesg
* talk
* tput
* uname
* who
* write

Text processing|

* awk
* basename
* comm
* csplit
* cut
* diff
* dirname
* ed
* ex
* fold
* head
* iconv
* join
* m4
* more
* nl
* paste
* patch
* printf
* read
* sed
* sort
* strings
* tail
* tr
* troff
* uniq
* vi
* wc
* xargs

Shell builtins|

* alias
* cd
* echo
* test
* unset
* wait

Searching|

* find
* grep

Documentation|

* man

Software development|

* ar
* ctags
* lex
* make
* nm
* strip
* yacc

Miscellaneous|

* bc
* cal
* expr
* lp
* od
* sleep
* true and false

* Categories
* Standard Unix programs
* Unix SUS2008 utilities
* List

* v
* t
* e

GNU Core Utilities command-line interface programs

File system|

* chcon
* chmod
* chown
* chgrp
* cksum
* cp
* dd
* df
* dir
* dircolors
* install
* ln
* ls
* mkdir
* mkfifo
* mknod
* mktemp
* mv
* realpath
* rm
* rmdir
* shred
* sync
* touch
* truncate
* vdir

Text utilities|

* b2sum
* base32
* base64
* cat
* cksum
* comm
* csplit
* cut
* expand
* fmt
* fold
* head
* join
* md5sum
* nl
* numfmt
* od
* paste
* ptx
* pr
* sha1sum
* shuf
* sort
* split
* sum
* tac
* tail
* tr
* tsort
* unexpand
* uniq
* wc

Shell utilities|

* arch
* basename
* chroot
* date
* dirname
* du
* echo
* env
* expr
* factor
* false
* groups
* hostid
* id
* link
* logname
* nice
* nohup
* nproc
* pathchk
* pinky
* printenv
* printf
* pwd
* readlink
* runcon
* seq
* sleep
* stat
* stdbuf
* stty
* tee
* test
* timeout
* true
* tty
* uname
* unlink
* uptime
* users
* who
* whoami
* yes

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template