Scheduling
The second big topic I want to cover in this chapter is scheduling. The Linux scheduler has a queue of threads that are ready to run, and its job is to schedule them on CPUs as they become available. Each thread has a scheduling policy that may be time-shared or real-time. The time-shared threads have a niceness value that increases or reduces their entitlement to CPU time. The real-time threads have priority in that a higher priority thread will preempt a lower one. The scheduler works with threads, not processes. Each thread is scheduled regardless of which process it is running in.
The scheduler runs when any of the following occurs:
- A thread is blocked by calling
sleep()
or another blocking system call - A time-shared thread exhausts its time slice
- An interruption causes a thread to be unblocked, for example, because of
I/O completing
For background information on the Linux scheduler, I recommend that you read the chapter on process scheduling...