ArticleslgStudy

computer science

Nice (Unix)

Nice (Unix) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Nice (Unix) rather than just read about it. In short: 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.

Key takeaways

  • Nice (Unix) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Nice (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Nice (Unix) from memory before moving on to harder problems.

Reference excerpt

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

Etymology 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's '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's 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.

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. 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. If a user wanted to compress a large file without slowing down other processes, they might run the following:

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's 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.

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.

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

References

External links

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

Worked examples

Example 1 — a first encounter with Nice (Unix)

Start with the simplest possible case. Write down what Nice (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Nice (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Nice (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Nice (Unix)

In research
Nice (Unix) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Nice (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Nice (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Unix SUS2008 utilities, Unix process- and task-management-related software, so understanding it makes those chapters shorter.
In everyday life
Look for Nice (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Nice (Unix)” →

How to study Nice (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Nice (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Nice (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Nice (Unix) in simple terms?

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.

Why does Nice (Unix) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Nice (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Nice (Unix).

Tags

  • Unix SUS2008 utilities
  • Unix process- and task-management-related software

Keep exploring