November 19, 2022

The Nice Command and How to Use It

The nice command changes the priority of a process. A process with a lower priority will get less CPU time than a process with a higher priority.

The priority of a process can be a number between -20 and 19. A lower number means a higher priority. The default priority is 0.

Here is an example. This command will start the “sleep” command with a priority of 10:

$ nice -n 10 sleep 100

The “sleep” command will sleep for 100 seconds. While it is sleeping, other processes will get more CPU time than usual.

You can use the “top” command to see the priority of a process:

$ top

The “nice” command can be used to give a process a lower priority, so that it gets less CPU time.

The “renice” command can be used to change the priority of a running process.

The “nice” and “renice” commands can only be used by the root user, or by a user with the “CAP_SYS_NICE” capability.

Related commands

ionice – set or get process I/O scheduling class and priority

ps – report a snapshot of the current processes

renice – alter priority of running processes

top – display Linux tasks

Written by Sushanth, personal technology columnist and founder of Logical Bee. You can follow him on the social web or sign up for the email newsletter for your daily dose of how-to guides and video tutorials.



0 Comments: