nice and ionice. Process Priorities

nice – allows you to specify the priority of the processor performing various tasks, the range of priorities is -20 to 19, where 19 is the smallest, if not specified, then there will be a standard priority of 0. Convenient for example when packing data into archives so that this task does not load the server or when many processes need to be started, distributing the load, which occupy all CPU time.

Example of the execution of the command with the lowest priority:

nice -n 19 COMMAND

See the table of processes and their priorities as follows (column NI):

ps axl
ps -l

If the table is large, you can redirect the output of the command to Less and look at the page:

ps axl | less

To change the priority:

renice -n 19 PROCESS(PID)

Checking the default priority value (standard 0):

nice

ionice – allows you to specify the priority for I/O operations, for example, to reduce the load on the disk. The first class is from 1 to 3, then the priority is from 0 to 7, where 7 is the smallest.
There are three classes:
1) Real time – Preemptive without paying attention to other processes, indicating priorities from 0 to 7.
2) Best Effort — Standard with priorities from 0 to 7.
3) Idle — With idle time without priority.

Example of executing the command with the lowest I/O priority:

ionice -c2 -n7 COMMAND

To change the priority:

ionice -c2 -n7 -p PROCESS(PID)

To view the set priority:

ionice -p PROCESS(PID)

You can specify priorities at the same time via nice and ionice:

nice -n 19 ionice -c2 -n7 COMMAND

To specify high priorities, for example, you might need root permissions, this command should be executed as root user or added before the sudo command.

Leave a comment

Leave a Reply

Discover more from IT Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading