CPU Scheduling in OS – Scheduler and Dispatcher

Types of CPU Scheduling, Long-term, Short-term and, Medium-term Scheduler, Dispatcher, and CPU Scheduling Criteria discussed.

CPU Scheduling in operating system

CPU Scheduling in operating systems is a fundamental function, and almost all computer resources are scheduled before use. The CPU is also one of the primary resources. So, CPU scheduling before use. The Scheduling Algorithms determine how the CPU will be allocated to the process.

CPU Scheduling in OS

What is CPU Scheduling?

CPU scheduling in the operating system is the basis of the multi-programmed operating system. The idea of multiprogramming is relatively simple if a process(job) is waiting for an I/O request, then the CPU switches from one process to another through a dispatcher, so the CPU is always busy in multiprogramming.

But in a simple computer system, the CPU sits idle until the I/O request is granted. By switching the CPU among processes, the OS can make the computer more productive.

Types of CPU Scheduling

CPU scheduling has two types-Non-Preemptive and Preemptive

Non-Preemptive Scheduling

In non-preemptive scheduling, once the CPU is assigned to a process, the processor does not release it until the completion of that process. The CPU will be assigned to another job only after the previous one has finished.

Preemptive Scheduling

In the preemptive scheduling algorithm, the CPU can release the process even in the middle of the execution. For example, the CPU executing the process P1, in the middle of the execution the CPU receives a request signal from process P2. Then the OS compares the priorities of P1 and P2.

CPU Scheduler in OS

There are three types of CPU schedulers in an operating system. These are long-term schedulers, short-term schedulers, and mid-term schedulers.

Long-term Scheduler

The function of a long-term scheduler is to select the jobs from the pool of jobs and load these jobs into the main memory(Ready Queue) of that computer, so the long-term scheduler is also called a job scheduler.

Short-term Scheduler

The function of a short-term scheduler is to select a job from the ready queue and give control of the CPU to that process with the help of a “Dispatcher”. That’s why the short-term scheduler is also said to be the CPU scheduler.

The method of selecting a process from the ready queue by the short-term scheduler depends on the Scheduling algorithms.

Medium-term Scheduler

If a process requests an I/O in the middle of execution, then the process removed from the main memory is loaded into the waiting queue. When the I/O operation is completed, then the job is moved from the waiting queue to the ready queue. These two operations are performed by the medium-term scheduler.

Dispatcher in OS

A dispatcher is a module, that connects the CPU to the process selected by the short-term scheduler. The main function of the dispatcher is switching, it means switching the CPU from one process to another process.

Another function of the dispatcher is jumping to the proper location in the user program and ready to start execution. The time taken by the dispatcher to stop one process and start another running is called the Dispatch Latency in OS.

The degree of multiprogramming is dependent on the dispatch latency. If the dispatch latency is increasing, then the degree of multiprogramming decreases.

CPU Scheduling Criteria

Throughput

It means how many jobs are completed by the CPU.

Turnaround Time

The time interval between the submission of the process and the time of the completion is the turnaround time.

Turnaround time = Waiting time in the ready queue + executing time + waiting time in the waiting queue for I/O

Waiting Time

Waiting time is the sum of the periods spent waiting by a process in the ready queue.

Response Time

Response time is the time duration between the submission and the first response.

CPU Utilization

This is the percentage of time that the processor is busy, CPU utilization may range from 0-100%.