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.
There are five scheduling policy options:
- 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.
- SCHED_BATCH: This policy uses the Batch processes algorithm.
- SCHED_RR: This policy uses the Round Robin process algorithm.
- SCHED_IDLE: This policy used to run I/O jobs having less priority.
- 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):
(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.
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”.
(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:
To get help regarding the “chrt” command, use “–help” in terminal:
To check the version of the “chrt” command, execute the “–version” option in the terminal:
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.