Process scheduling is the activity of the process manager that handles the removal of the running process from the CPU and the selection of another process based on a particular strategy. Throughout its lifetime, a process moves between various scheduling queues, such as the ready queue, waiting queue or devices queue.
Scheduling is important in operating systems with multiprogramming as multiple processes might be eligible for running at a time.
One of the key responsibilities of an Operating System (OS) is to decide which programs will execute on the CPU.
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.
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.
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.
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.
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.
Frequently selects the next process to execute from the ready state.
Maintains fairness by allocating CPU time among processes.
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.
It is the fastest scheduler, since it operates very frequently (often every few milliseconds).
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. The following are functions of it.
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.