chrt command in Linux is known for manipulating the real-time attributes of a process. It sets or retrieves the real-time scheduling attributes of an existing PID, or runs the command with the given attributes.
$ chrt [options] priority command [argument ...] $ chrt [options] -p [priority] pid
- -b, –batch : Used to set policy to SCHED_BATCH.
- -d, –deadline : Used to set policy to SCHED_DEADLINE.
- -f, –fifo : Used to set policy to SCHED_FIFO.
- -i, –idle : Used to set policy to SCHED_IDLE.
- -o, –other : Used to set policy to SCHED_OTHER.
- -r, –rr : Used to set policy to SCHED_RR(default)
- SCHED_BATCH : Use Scheduling batch processes algorithm.
- SCHED_FIFO : Uses First In-First Out scheduling algorithm. This scheduling method is used on Batch-Systems, it is NON-PREEMPTIVE. It implements just one queue which holds the tasks in the order they come in.
- SCHED_IDLE: Used for running very low priority background jobs.
- SCHED_OTHER: Uses Default Linux time-sharing scheduling algorithm or simply the standard round-robin time-sharing policy.
- SCHED_RR Uses Round Robin scheduling algorithm and is used as the default algorithm if not specified. It is an algorithm used for PREEMPTIVE scheduling.
- -a, –all-tasks: It is used to operate on all the tasks(threads) for a given pid.
- -m, –max: Used to show min and max valid priorities.
- -p, –pid: Operate on existing given pid.
- -v, –verbose: Used to show the status information.
- -h, –help: Used to show the help message and exit.
- -v, –version: Used to show the version information and exit.
- To see the current scheduling policy: First we have to make a process. Let’s take a example, Firefox is running and to find its’s pid we run the following command:
$ pidof -s firefox
In my case the pid is 5794, here is the image
Now to retrieve the current scheduling policy and priority for the firefox process, use chrt in the following way:
$ chrt -p 5794
- To change the scheduling policy to SCHED_FIFO: From the above example, the scheduling policy of firefox process is set as SCHED_OTHER. Now to change the policy to SCHED_FIFO we can use the following command:
$ sudo chrt -f -p 5794
- To change the scheduling policy SCHED_BATCH: From the above example, the scheduling policy of the firefox process is set as SCHED_FIFO. Now to change the policy to SCHED_BATCH we can use the following command:
$ sudo chrt -b -p 5794
- To see the maximum and minimum valid priorities: This can be done using the -m command line option mentioned in the policy of chrt.
$ chrt -m