Linux nice Command: Set a New Process's Scheduling Priority

nice specifies the nice value used for CPU scheduling when starting a new command. A nice value higher than the default generally indicates a tendency to yield the CPU to other tasks more easily.

What is the nice command?

The typical range of nice values in Linux is from -20 to 19, with lower values indicating higher priority. nice does not change processes that are already running. Use renice for running tasks.

Basic syntax

nice -n adjustment_value command [arguments...]

The installed implementation and options may vary depending on the distribution. Check your system's documentation with man nice.

Examples

Start with low priority

Start a read operation with a nice value 10 higher than the default.

nice -n 10 sha256sum large.log

Start with the default increment

In the GNU implementation, if the adjustment value is omitted, the default increment is used.

nice sha256sum large.log

Check the actual value

Check the NI column of the running process.

ps -p 1234 -o pid,ni,cmd

Checking the nice value of a new process

nice sets the scheduling nice value of a newly started process. The following is an example of starting a test sleep with a value of 10 and then checking it.

nice -n 10 sleep 60 &
ps -o ni,comm -p $!

Example output:

 NI COMMAND
 10 sleep

$! is the PID of the most recent background process. Generally, the higher the number, the lower the CPU scheduling priority, but this does not mean a limit on CPU usage. To change the value of a process that is already running, use renice.

Main Options and Format

Options/Format Description
-n value Specifies the adjustment value for the new command based on the existing nice value.
--adjustment=value Long option format in the GNU implementation.
run without arguments Displays the current nice value in the GNU implementation.

Precautions when using

The nice value is a hint for CPU scheduling; it does not guarantee execution time or change memory or disk I/O priorities. Raising priority by lowering the nice value may not be allowed for regular users. For major load issues, first check the cause process and the type of resource.

Frequently Asked Questions

Does nice -n 10 make it 10 times faster?

No. A higher value generally means a lower CPU priority, and it does not indicate a fixed multiple of processing speed.

Official Documentation

The exact behavior of the option and implementation differences can be found in the official documentation for nice.

More in This Category
Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux Tutorial / How the Shell Runs Commands: ;, &&, ||, Aliases, and Environment Variables

Linux Tutorial / How the Shell Runs Commands: ;, &&, ||, Aliases, and Environment Variables

Learn how Bash resolves commands and uses exit status with ;, &&, and ||, then distinguish aliases, shell variables, and exported environment variables.

Linux w Command: Show Logged-In Users and Their Processes

Linux w Command: Show Logged-In Users and Their Processes

Learn how to show Logged-In Users and Their Processes with the Linux w command, including practical examples, key options, and important precautions.

Linux nice Command: Set a New Process's Scheduling Priority

Linux nice Command: Set a New Process's Scheduling Priority

Learn how to set a New Process's Scheduling Priority with the Linux nice command, including practical examples, key options, and important precautions.

Linux date Command: Display and Format the Current Time

Linux date Command: Display and Format the Current Time

Learn how to display and Format the Current Time with the Linux date command, including practical examples, key options, and important precautions.

Linux wget Command: Download Files from URLs

Linux wget Command: Download Files from URLs

Learn how to download Files from URLs with the Linux wget command, including practical examples, key options, and important precautions.

Linux df Command: Check Filesystem Free Space

Linux df Command: Check Filesystem Free Space

Learn how to check Filesystem Free Space with the Linux df command, including practical examples, key options, and important precautions.

Linux bunzip2 Command: Decompress bzip2 Files

Linux bunzip2 Command: Decompress bzip2 Files

Learn how to decompress bzip2 Files with the Linux bunzip2 command, including practical examples, key options, and important precautions.

Linux whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux kill Command: Send a Signal to a Process ID

Linux kill Command: Send a Signal to a Process ID

Learn how to send a Signal to a Process ID with the Linux kill command, including practical examples, key options, and important precautions.