A scheduler is a key component of kernel. It has algorithms that determine which task executes when. Scheduler uses following entities/ policies for task scheduling.
i) Scheduling Entities:
- Any task that can be scheduled for execution is a scheduling entity.
- Example: ISR, a function or any process.
- When a scheduling entity enters ready state, it is scheduled to be executed by the processor.
ii) Multitasking:
- The kernel schedules multiple tasks such that many tasks appear to be executing concurrently.
- The scheduler must ensure that appropriate task is executed without any latency.
iii) Context switching:
- Whenever a task is in execution, the register holds the contents of that task.
- Whenever the OS decides to switch the task, it needs to store this context (contents of ongoing task).
- For this OS uses special memory block called Task Control Block (TCB).
- In TCB, OS stores all the information required by itself and the task for execution.
iv) Dispatcher:
- It is responsible for dispatching the tasks in running state.
- It controls task switching and execution flow.
v) Scheduling algorithms:
- It implements scheduling algorithm to determine which task will run.
- There are two types of scheduling algorithms –
a) Preemptive priority based scheduling:
If higher priority task enters ready state, then it preempts or suspends the lower priority task and higher priority task enters execution state.
b) Round Robin scheduling:
Each task is given fixed time slot.