Process Scheduler
Process Schedulers are fundamental components of operating systems responsible
for deciding the order in which processes are executed by the CPU. In simpler
terms, they manage how the CPU allocates its time among multiple tasks or
processes that are competing for its attention.
Types of Process Schedulers
There are three types of process schedulers:
1. Long-Term Scheduler (Job Scheduler)
2. Short-Term Scheduler (CPU Scheduler)
3. Medium-Term Scheduler
1. Long-Term Scheduler (Job Scheduler)
The Long-Term Scheduler is responsible for loading processes from disk into main
memory so they can begin execution. When a new process is admitted, it moves
into the Ready state.
Key Functions
Transfers processes from the Job Queue to the Ready Queue.
Controls the degree of Multi-programming — the number of processes
present in memory or ready state at any time.
Carefully selects a balanced mix of I/O-bound and CPU-bound processes to
ensure efficient system performance.
Helps avoid a situation where either the CPU or I/O devices remain idle.
In many modern time-sharing systems (such as Windows), a long-term
scheduler may not exist; new processes are directly admitted to memory for
short-term scheduling.
Performance
It is the slowest among all schedulers, as it operates less frequently.
2. Short-Term Scheduler (CPU Scheduler)
The Short-Term Scheduler (STS) is responsible for selecting a process from the
ready queue and assigning the CPU to it.
Key Functions
Frequently selects the next process to execute from the ready state.
Ensures no process suffers from starvation.
Uses various CPU scheduling algorithms to decide process order.
Maximizes CPU utilization by keeping the processor as busy as possible.
Calls the dispatcher, which performs the actual context switch.
Performance
It is the fastest scheduler, since it operates very frequently (often every few
milliseconds).
The dispatcher is responsible for loading the process selected by the Short-term
scheduler on the CPU (Ready to Running State). Context switching is done by the
dispatcher only. A dispatcher does the following work:
Saving context (process control block) of previously running process if not
finished.
Switching system mode to user mode.
Jumping to the proper location in the newly loaded program.
Note: Time taken by dispatcher is called dispatch latency or process context switch
time.
Short-Term Scheduler
2.1 Dispatcher
The Dispatcher is a special program that takes over once the short-term scheduler
selects a process. It transfers control of the CPU to the chosen process.
Functions of the Dispatcher
Context Switching: Saves the state of the previously running process and
restores the state of the new one.
Mode Switching: Ensures correct transition into user mode from kernel
mode.
Program Control Transfer: Jumps to the correct starting point in the newly
selected program.
Dispatcher Example
Using FCFS scheduling for processes P1 → P2 → P3 → P4:
Scheduler selects P1 first.
Dispatcher loads P1 onto the CPU.
Next the scheduler selects P2, and the dispatcher assigns P2 to the CPU, and
so on.
Note
The time taken by the dispatcher to perform context switching is
called dispatch latency.
Dispatcher
3. Medium-Term Scheduler
The Medium-Term Scheduler (MTS) manages swapping, which temporarily moves
processes between main memory and disk.
Key Functions
Swaps processes out of memory when they are waiting (e.g., blocked for
I/O) to reduce the degree of multiprogramming.
Frees memory for other active processes.
Swaps processes back into memory when they are ready to continue
execution, allowing them to resume from where they left off.
Helps maintain an effective mix of CPU-bound and I/O-bound processes.
Performance
It operates faster than the long-term scheduler but slower than the short-term
scheduler.
Medium-Term Scheduler
Comparison Among Scheduler
Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler
It is a process-swapping
It is a job scheduler It is a CPU scheduler
scheduler
Its speed lies between
It is the slowest It is the fastest
long-term and short-term
scheduler scheduler
schedulers
It gives less control
It controls the degree of It reduces the degree of
over the degree of
multiprogramming multiprogramming
multiprogramming
It is barely present or
It is essential for time- It is a component of
nonexistent in time-
sharing systems time-sharing systems
sharing systems
It selects processes from It selects ready It can re-introduce
the job pool and loads processes for execution processes into memory
them into memory by the CPU and resume execution