The Linux® operating system supports various scheduling policies. The default universal time sharing scheduling policy is SCHED_OTHER, which is used by most threads. SCHED_RR and SCHED_FIFO can be used by threads in real-time applications. .
The kernel decides which is the next runnable thread to be run by the CPU. The kernel maintains a list of runnable threads. It looks for the thread with the highest priority and selects that thread as the next thread to be run.
ps -emo pid,ppid,policy,tid,comm,rtprio,cputimewhere policy:
PID PPID POL TID COMMAND RTPRIO TIME 31531 30800 - - java - 00:00:13 - - RR 31531 - 6 00:00:00 - - RR 31532 - 6 00:00:13 - - RR 31533 - 6 00:00:00 - - RR 31538 - 6 00:00:00 - - RR 31539 - 6 00:00:00 - - RR 31540 - 6 00:00:00 - - RR 31541 - 6 00:00:00 - - RR 31542 - 6 00:00:00 - - RR 31543 - 6 00:00:00 - - RR 31544 - 6 00:00:00 - - RR 31545 - 6 00:00:00 - - RR 31546 - 6 00:00:00This output shows the Java™ process, and numerous threads with policy SCHED_RR and priority 6.
SCHED_OTHER uses time slicing, which means that each thread runs for a limited time period, after which the next thread is allowed to run.
If a SCHED_FIFO process that has a higher priority becomes available, it preempts an existing SCHED_FIFO process if that process has a lower priority. This thread is then kept at the top of the queue for its priority.
There is no time slicing.
For details on these Linux scheduling policies, see the man page for sched_setscheduler. To query the current scheduling policy, use sched_getscheduler, or the ps command shown in the example.
For more information about processes, see Examining process information.