nice Command: Tutorial & Examples

Run a command with a modified scheduling priority

The nice command is a utility in Linux that allows you to run a command with a modified scheduling priority. Scheduling priority determines the order in which processes are allocated CPU time. By default, processes are given a priority of 0, but the nice command allows you to specify a different priority level, ranging from -20 (highest priority) to 19 (lowest priority).

Here is the basic syntax for using nice:

nice [options] command [arguments]

The command argument is the command that you want to run with a modified scheduling priority, and the arguments are any additional arguments that the command requires.

The most important option for nice is this one:

  • -n increment: Specifies the increment to the scheduling priority. The default is 10.

Here is an example of using nice to run the sleep command with a lower scheduling priority:

nice -n 15 sleep 60

This command will run the sleep command with a scheduling priority of 15, causing it to be run after processes with higher priority. The sleep command will pause the terminal for 60 seconds.

It's worth noting that the nice command can only lower the scheduling priority of a process. To increase the scheduling priority of a process, you will need to use the renice command.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA