Adjust Process Scheduling

Red Hat Enterprise LinuxBeginner
Practice Now

Introduction

In this challenge, you will explore how to manage process scheduling on a Linux system. Process scheduling is a key function of the operating system that determines which process gets to use the CPU and for how long. As a system administrator, you can influence this scheduling by adjusting process priorities. You will use the nice and renice commands to control process priority, a fundamental skill for optimizing system performance and ensuring critical applications receive the resources they need.

Start a Process with a Custom Priority

In Linux, every process has a "nice" value, which influences its scheduling priority. This value ranges from -20 (highest priority) to 19 (lowest priority). The nice command allows you to run a new command with a specified nice value. Note that only the root user (or a user with sudo privileges) can set a negative nice value to increase a process's priority.

Tasks

  • Use the nice command to start a new sleep 600 process in the background.
  • Assign the new process a high priority with a nice value of -10.
  • Verify the priority of the new process using the ps command.

Requirements

  • The command to run is sleep 600.
  • The process must be started with a nice value of -10.
  • You must use sudo to assign a negative nice value.
  • The process must be run in the background so you can continue to use the terminal.

Example

After starting the process, the output of ps -e -o pid,ni,comm | grep sleep should show the sleep process with a NI (nice) value of -10. The PID will vary.

ps -e -o pid,ni,comm | grep sleep
   2250 -10 sleep

You can also use ps -e -o pid,ni,comm to see all processes and their nice values:

  PID  NI COMMAND
    1   0 systemd
 2188   0 bash
 2250 -10 sleep

Adjust Priority of a Running Process with renice

Sometimes you need to change the priority of a process that is already running. For this, you can use the renice command. Similar to nice, you need sudo privileges to increase the priority (set a lower or more negative nice value) of a process. You also need sudo to change the priority of a process owned by another user, such as root.

Tasks

  • Find the Process ID (PID) of the sleep 600 process you started in the previous step.
  • Use the renice command to change its priority to a lower priority, with a nice value of 5.
  • Verify the new priority level using the ps command.

Requirements

  • The target process is the sleep 600 process from the previous step.
  • The new nice value must be 5.
  • You must use sudo to change the priority of the process (since it was started with sudo and is owned by root).

Example

After running the renice command, the output of ps -e -o pid,ni,comm | grep sleep should show the sleep process with a new NI value of 5.

ps -e -o pid,ni,comm | grep sleep
   2250   5 sleep

You can also use ps -e -o pid,ni,comm to see all processes:

  PID  NI COMMAND
    1   0 systemd
 2188   0 bash
 2250   5 sleep

Summary

In this challenge, you have learned the fundamentals of adjusting process scheduling priorities on a Linux system. You practiced using the nice command to launch a new process with a specific priority and the renice command to modify the priority of an already running process. You also learned that increasing a process's priority (setting a negative nice value) requires administrative privileges (sudo). These skills are essential for system administration and performance tuning.

✨ Check Solution and Practice✨ Check Solution and Practice