How to use chrt command

You can use chrt command to set or retrieve the real time scheduling attributes-scheduling priority of an existing pid. You can also run command with the given attributes.

First of all you need to know,

  1. SCHED_FIFO: First in, first out, real time processes.
  2. SCHED_RR: Round robin real time processes.
  3. SCHED_OTHER: Normal time/schedule sharing.
  4. SCHED_BATCH: Almost the same as the SCHED_OTHER, but the process is considered always the most cpu consuming.

To get / retrieve the real-time attributes of an existing task / PID, enter:

$ chrt -p pid

For example,

$ pidof firefox
17588
$ chrt -p 17588
pid 17588's current scheduling policy: SCHED_OTHER
pid 17588's current scheduling priority: 0
  • How do I use chrt command to set real time attributes of a Linux process?
$ sudo chrt -p prio pid

For example,

$ sudo chrt -p 20 17588
  • To set scheduling policy to SCHED_BATCH (-b or --batch), for example:
$ chrt -b -p 0 17588
  • To set scheduling policy to SCHED_FIFO (-f or --fifo), for example:
$ sudo chrt -f -p 20 17588

Note: Range of number is [1-99]=>20.

  • To set policy scheduling policy to SCHED_OTHER (-o or --other), for example:
$ chrt -o -p 0 17588
  • To set scheduling policy to SCHED_RR (-r or --rr), for example:
$ sudo chrt -r -p 50 17588

Note: Range of number is [1-99]=>50.

Note: Setting a realtime scheduling policy (SCHED_RR or SCHED_FIFO) requires root permissions, so you either have to be root or run it with sudo.

  • Before setting new scheduling policy, you need to find out min and max valid priorities for each scheduling algorithm, show min and max valid priorities. For example,
$ chrt -m
SCHED_OTHER min/max priority	: 0/0
SCHED_FIFO min/max priority	: 1/99
SCHED_RR min/max priority	: 1/99
SCHED_BATCH min/max priority	: 0/0
SCHED_IDLE min/max priority	: 0/0

See man page: man chrt (1): manipulate the real-time attributes of a process

1 Like