How to Use Linux Chrt Command?

41

While using Linux operating system, multiple programs wait to be converted into a process for execution. When a program changes into a process, a lot of attributes are set that can be manipulated. For this, the Linux system provides a helpful tool to set or fetch real-time attributes of a process.

The “chrt” command is a part of a low-level Linux utility that is not only used to set attributes on runtime but also to change the scheduling policy of a process and set its priority. It uses the existing PID of any waiting program to set and retrieve a schedule of real-time attributes. Simply, the scheduler decides which process is executed by the CPU first when the “chrt” command changes its priority.

Scheduling Algorithms:

There are five scheduling policy options:

  1. SCHED_FIFO: This policy uses the “First In_First Out” algorithm. It is a real-time process that supports only one queue which is the order of processes.
  2. SCHED_BATCH: This policy uses the Batch processes algorithm.
  3. SCHED_RR: This policy uses the Round Robin process algorithm.
  4. SCHED_IDLE: This policy used to run I/O jobs having less priority.
  5. SCHED_OTHER: This policy uses the default Linux-time_sharing scheduling algorithm.

Chrt Command Syntax

The syntax of the “chrt” command utility is:

“ $ chrt [options] -p [priority] pid”

Chrt Command with Options

To check the current scheduling policy and priority of any running program, find its pid first using the chrt command.

For example, to get the pid of “calibre”, execute the given command:

(calibre is a running program in my system, you can select any other program).

Current Policy and Priority of Process

To get the current scheduling process and priority of the program, use “pid” (we got in the above section):

How to Use Linux Chrt Command? 1618074721 730 How to Use Linux Chrt Command

(In my selected program, the current scheduling process is “Sched_Batch” and its priority is 0)

Algorithm’s Valid Min/Max Priority

To get minimum and maximum priorities of scheduling policies, use the “-m” option.

How to Use Linux Chrt Command? 1618074722 634 How to Use Linux Chrt Command

Change Scheduling Policy “SCHED_FIFO” with Priority

To change the scheduling policy of a process and set its priority level, execute the below-mentioned option with the chart command.

For example, the current schedule of the program is “Sched_Batch” and we want to change it to “Sched_Fifo”.

How to Use Linux Chrt Command? 1618074722 981 How to Use Linux Chrt Command

(in this command, I set the priority level at 15, you can set it according to your choice).

Change Scheduling Policy “SCHED_IDLE” with Priority

We set the scheduling policy of the “calibre” to “SCHED_FIFO”, now to change it to “SCHED_IDLE” use the given command:

How to Use Linux Chrt Command? 1618074722 681 How to Use Linux Chrt Command

Display Help

To get help regarding the “chrt” command, use “–help” in terminal:

How to Use Linux Chrt Command? 1618074723 74 How to Use Linux Chrt Command

Display Version

To check the version of the “chrt” command, execute the “–version” option in the terminal:

How to Use Linux Chrt Command? 1618074724 222 How to Use Linux Chrt Command

Conclusion:

We have briefly discussed the “chrt” command with multiple options. The “chrt” command is a low-level helpful Linux tool used to set the schedule and priority of a process waiting in the background and ready to go for running state.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More