Dispatcher provides control of the CPU to the process picked by the short-term scheduler. When the scheduler finishes its task of selecting a process, then the dispatcher takes that process to the destination state.
For example,
Suppose there are 5 processes P1, P2, P3, P4, and P5.
The arrival times of these processes are T1, T2, T3, T4, and T5.
Here, FIFO (first in first out) algorithm is used. So, P1 comes first, and then the scheduler will choose that it is the first process that is going to execute. The dispatcher will eliminate P1 from ready queue and take it to the CPU.
Now, the scheduler will select P2, which will be executed after P1. The dispatcher removes P2 from the ready queue and gives it to the CPU.
This carries on in a similar way for processes P3, P4, and P5.
This is how a dispatcher works. The scheduler provides the dispatcher with an ordered list of processes that the dispatcher gives to the CPU. The dispatcher does many tasks such as memory mapping, context switching and setting up user registers.
What is Dispatcher?
The dispatcher is a crucial component of an operating system’s CPU scheduling system. It’s the module that gives control of the CPU to the process selected by the short-term scheduler. This function involves a context switch, switching to user mode, and jumping to the proper location in the user program to restart that program. The dispatcher effectively manages the transition from one process to another.
Functions of Dispatcher
- Context Switching: The dispatcher saves the state (context) of the currently executing process and loads the saved state of the next process to run. This context includes CPU registers, program counters, and memory management information.
- Switching to User Mode: Processes run in user mode, where they have restricted access to system resources. The dispatcher switches the CPU to user mode before handing control over to the process to ensure safe execution of user programs.
- Jumping to the Correct Location: The dispatcher moves the program counter to the position where the process was last interrupted. This ensures the process resumes execution from the correct state, not starting over from the beginning.
- Managing Process State: The dispatcher changes the state of the process from ‘ready’ to ‘running’ and updates various scheduling and management tables used by the operating system.
- Prioritizing CPU Allocation: In systems with priority-based scheduling, the dispatcher may consider the priority of processes, ensuring that high-priority processes receive CPU time before lower-priority ones.
- Accounting: The dispatcher updates system and process accounting information. This includes tracking CPU usage, waiting time, and overall system load, which can be used for performance tuning and ensuring fairness.
- Memory Management Adjustments: In some cases, switching processes may require changes to memory management settings, such as refreshing the memory map to reflect the memory allocation of the incoming process.