What is CPU Scheduling and Various Schedulers in Operating System

What is CPU Scheduling and Various Schedulers in Operating System

CPU Scheduling is the basis of a 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 that job to another job, 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 Operating System can make the computer more productive.

Scheduling is a fundamental operating system function, almost all computer resources are scheduled before use. The CPU is also one of the primary resources. So CPU is also scheduled before use. The CPU scheduling algorithm determines how the CPU will be allocated to the process.

CPU scheduling algorithms are two types one is non-preemptive and preemptive scheduling algorithms.

  • 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 some other job only after the previous job has finished.
  • In preemptive scheduling, the CPU can release the processes even in the middle of the execution.

For example, the CPU executes process P1, and in the middle of the execution the CPU received a request signal from process P2, Then the operating system compares the priorities of P1 and P2. If the priority of P1 is higher than the P2 then the CPU continues the execution of process P1. Otherwise [priority (P1 < P2)] the CPU preempts the process P1 and is assigned to process P2.

The operating system has many schedulers. There are 3 main schedulers:

  1. Long term Scheduler
  2. Short term Scheduler
  3. Medium-term Scheduler

Long Term Scheduler

The function of the long-term scheduler selects the jobs from the pool of jobs and loads these jobs into the main memory (ready queue) of the 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 gives 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 is depending on the Scheduling algorithms.

Dispatcher in OS

A dispatcher is a module, it 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.

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.


Scheduling Methodology

Following are some performance metrics of the scheduling algorithms.

Throughput: It means how many jobs are completed by the CPU within the time period.

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 ready queue + executing time + waiting time in waiting for the queue for I/O

Waiting Time: Waiting time is the sum of the periods spent waiting for a process in the ready queue. The least average waiting time is said to be the best algorithm.

Response Time: Response time is the time duration between the submission and the first response. For example, the process entered the ready queue at 10:05 AM. But the process got its first response at 10:10 AM. The interval between 10:05 to 10:10 is the response time.

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top