Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


RHCSA - Operate Running Systems: Adjust Process Scheduling

The kernel scheduler is responsible for assigning priorities to processes, determining their execution order. By adjusting process scheduling, the system can optimize resource allocation and give proper attention to critical tasks while reducing attention to non-critical ones. Linux offers various tools to manage process priorities, such as the nice and renice commands.

With the nice command, users can initiate a new process with a specified priority level, while the renice command enables the modification of priority for existing processes. These commands are highly valuable for fine-tuning CPU time allocation to processes and enhancing overall system performance.

A higher nice value means a lower priority, while a lower nice value means a higher priority. The priority values range from -20 (highest priority) to 19 (lowest priority).

Only when run as root or when using sudo can you set a higher priority against a process.

Have two terminals open to follow along with the exercises in this lesson.

Using the nice Command

In this section you will practice using the nice command and using the ps command to check a processes nice value.

Run a process with the lowest priority scheduling:

In terminal one, run the sleep command with the lowest possible priority:

nice -n 19 sleep 1000

In terminal two, view the assigned priority for the process:

ps -eo pid,nice,args | egrep 'NI|sleep'

The output will show 19 in the NI (nice) column:

 PID  NI COMMAND
4409  19 sleep 1000
4420   0 grep -E --color=auto NI|sleep

In terminal one, press Ctrl+C to end the sleep process.

Run a process with the highest priority scheduling:

In terminal one, run the sleep command with the lowest possible priority (enter your password if prompted):

sudo nice -n -20 sleep 2000

In terminal two, view the assigned priority for the process:

ps -eo pid,nice,args | egrep 'NI|sleep'

The output will show -20 in the NI (nice) column:

 PID  NI COMMAND
4494   0 sudo nice -n -20 sleep 2000
4503 -20 sleep 2000
4505   0 grep -E --color=auto NI|sleep

In terminal one, press Ctrl+C to end the sleep process.

Using the renice Command

In this section you will practice using the renice command and using the ps command to check a processes nice value.

Lower the priority of an existing process:

In terminal one, run the sleep command as normal:

sleep 3000

In terminal two, view the assigned priority for the process:

ps -eo pid,nice,args | egrep 'NI|sleep'

The output will show 0 in the NI (nice) column:

 PID  NI COMMAND
4610   0 sleep 3000
4612   0 grep -E --color=auto NI|sleep

Use the renice command to lower the priority of the sleep command. The output of your ps command above will show the PID you need to use:

renice -n 19 PID

The output of the renice command will show that the process priority changed:

4610 (process ID) old priority 0, new priority 19

In terminal one, press Ctrl+C to end the sleep process.

Increase the priority of an existing process:

In terminal one, run the sleep command as normal:

sleep 4000

In terminal two, view the assigned priority for the process:

ps -eo pid,nice,args | egrep 'NI|sleep'

The output will show 0 in the NI (nice) column:

 PID  NI COMMAND
4645   0 sleep 4000
4647   0 grep -E --color=auto NI|sleep

Use the renice command to increase the priority of the sleep command. The output of your ps command above will show the PID you need to use and enter your sudo password if prompted:

sudo renice -n -20 PID

The output of the renice command will show that the process priority changed:

4645 (process ID) old priority 0, new priority -20

In terminal one, press Ctrl+C to end the sleep process.


Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.