Home > Process Management > nice

nice: Run Programs with Adjusted Priority

Executes programs with adjusted system resource occupation priority (Niceness) when they are started. It is used to prevent low-priority tasks (e.g., backups, encoding) from slowing down the system, or conversely, to give precedence to critical tasks.

What is nice?

In Linux, process priority is expressed as 'Niceness'. The `nice` command executes a program by setting this value.

Understanding Niceness Values

A **higher** value indicates a **nicer** process, meaning it yields resources to other processes.

  • Range: -20 (highest priority/selfish) ~ 19 (lowest priority/yielding)
  • Default Value: 0 (standard priority)
  • Using Negative Values: Increasing priority (using negative values) requires root privileges.

Key Options (Shell)

Used by combining the priority value (`-n`) with the command to be executed.

1. Execute with Specified Priority

2. Help

Generated command:

Try combining the commands.

Description:

`nice` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Scenario Examples

Patterns used in practice to manage system load.

Run Backup with Low Priority (Yield Resources)

nice -n 10 tar -czf backup.tar.gz /var/www

When performing a large-scale compression (`tar`) operation, execute with a niceness value of 10 (yielding) to prevent other critical services, such as web servers, from slowing down.

Run with Very Low Priority

nice -n 19 ./heavy_computation.sh

By setting the maximum value of 19, the CPU is used only when the system is idle.

Run with High Priority (Root Privileges Required)

sudo nice -n -10 ./critical_service

Assigns a high priority (-10) to critical processes, allowing them to preempt the CPU. Setting negative values requires `sudo`.

Notation Caution

nice -n -5 command

When the option `-` meets a negative sign `-`, it might look like `-10`. `nice -10` is an old notation for `nice -n 10` (positive 10), so it's best to explicitly use `-n` to avoid confusion.

Installation

nice is a core command included in 'GNU Coreutils' and is pre-installed on almost all Linux distributions.

Verify Installation

Can be used immediately without separate installation.

Tips & Cautions

nice vs renice

Clearly understand the differences between the two commands.

  • nice: Assigns priority **when starting** a new command.
  • renice: Changes the priority of an **already running** process (PID).
  • How to Check: You can check the current process's niceness value in the `NI` column of `top` or `htop`.

Related commands

These are commands that are functionally similar or are commonly used together.



Same category commands