Changing scheduler priority using the nice command
Every task on a Linux system has a priority. The priority values range from -20 to 19. The lower the priority (-20), the more CPU time a task will be allocated. The default priority is 0.
Not all tasks need the same priority. An interactive application needs to respond quickly or it becomes difficult to use. A background task run via crontab
only needs to finish before it is scheduled to run again.
The nice
command will modify a task's priority. It can be used to invoke a task with modified priority. Raising a task's priority value will free resources for other tasks.
How to do it...
Invoking the nice
command with no arguments will report a task's current priority:
$ cat nicetest.sh echo "my nice is `nice`" $ sh nicetest.sh my nice is 0
Invoking the nice
command followed by another command name will run the second command with a niceness of 10
–it will add 10 to the task's default priority:
$ nice sh nicetest.sh my nice is 10
Invoking...