Understanding the nice Command

Basic Usage of nice

The nice command is used to run a command with modified scheduling priority. By default, processes in Linux run with a nice value of 0, which represents normal priority. The nice command allows users to lower (increase the nice value) or raise (decrease the nice value) the priority of a process.

nice [OPTION] [COMMAND [ARGUMENTS]]

Options Available with nice

-n n (Nice Value)

Set the nice value to n, which can range from -20 (highest priority) to 19 (lowest priority):

nice -n n [COMMAND]

--help

Display help information for the command:

nice --help

--version

Display the version information of the command:

nice --version

Examples of nice Command

Run a Command with Default Nice Value

nice sleep 10

This command runs the sleep command with the default nice value (0), delaying for 10 seconds.

Run a Command with a Lower Priority

nice -n 10 sleep 10

This command runs the sleep command with a nice value of 10, reducing its priority.

Run a Command with a Higher Priority

nice -n -5 sleep 10

This command runs the sleep command with a nice value of -5, increasing its priority.

Understanding Nice Values

The nice value can be set from -20 to 19:

Setting a higher nice value (e.g., 10) means the process will yield CPU time to others, while a lower nice value (e.g., -5) means it will prioritize this process over others.

Summary of Options

Option Description
-n n Set the nice value to n (from -20 to 19).
--help Display help information for the command.
--version Display the version information of the command.