Proccess 的 class


ps -L -o comm,pid,tid,class

bash              965   965 TS
ps               8711  8711 TS

By default programs run with Time Sharing (TS policy) on Linux.

Find RR class

ps x -L -o comm,pid,tid,class,rtprio,ni | grep RR

watchdog        11817 11817 RR       1   -




Each thread has an associated scheduling policy(ps 見到的 class)

sched_priority = 0 # It is not used in scheduling decisions (ps 見到的 rtprio)


Default Linux time-sharing scheduling

Thread under real-time policies always have priority over SCHED_OTHER

only static priority "sched_priority = 0"

The dynamic priority is based on the nice value (ps 的 ni)


The thread to run is chosen based on a dynamic priority that is determined only inside this list.

The dynamic priority is based on the nice value and is increased for each time quantum the thread is ready to run

sched_priority = 0


Scheduling very low priority jobs

sched_priority = 0

Real-Time Policies

sched_priority: 1 (low) ~ 99


needs the task to explicitly yield the processor


It is a simple enhancement of SCHED_FIFO

each thread is allowed to run only for a maximum time quantum (round-robin)

 * real-time threads always have higher priority than normal threads




chrt - show & manipulate the real-time attributes of a process

# -m, --max              # Show minimum and maximum valid priorities

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
SCHED_DEADLINE min/max priority : 0/0

# -p, --pid                # Show policy & priority of pid

chrt -p 11817

pid 11817's current scheduling policy: SCHED_RR
pid 11817's current scheduling priority: 1

set policy & priorities

  • -b, --batch            # Set scheduling policy to SCHED_BATCH
  • -f, --fifo                # Set scheduling policy to SCHED_FIFO
  • -i, --idle                # Set scheduling policy to SCHED_IDLE
  • -o, --other            # Set policy scheduling policy to SCHED_OTHER
  • -r, --rr( Default )   # Set scheduling policy to SCHED_RR. 


# setting SCHED_RR require root permissions

chrt -r -p [1..99] {pid}