0% found this document useful (0 votes)
212 views

Preemptive and Non Preemptive Scheduling

This document outlines CPU scheduling concepts and algorithms. It discusses basic scheduling concepts like CPU-I/O burst cycles and preemptive vs. non-preemptive scheduling. It then summarizes common scheduling algorithms like first come first serve (FCFS), shortest job first (SJF), priority scheduling, and round-robin scheduling. For each algorithm, it provides examples of how they work and their advantages/disadvantages.

Uploaded by

prathyusha43
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views

Preemptive and Non Preemptive Scheduling

This document outlines CPU scheduling concepts and algorithms. It discusses basic scheduling concepts like CPU-I/O burst cycles and preemptive vs. non-preemptive scheduling. It then summarizes common scheduling algorithms like first come first serve (FCFS), shortest job first (SJF), priority scheduling, and round-robin scheduling. For each algorithm, it provides examples of how they work and their advantages/disadvantages.

Uploaded by

prathyusha43
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

Chapter 5 CPU Scheduling

Bernard Chen Spring 2007

Outline
  

Basic Concepts Scheduling Criteria Scheduling Algorithms

Basic Concepts


The objective of multiprogramming is to have some process running at all times Scheduling of this kind is a fundamental operating-system function

CPU-I/O Burst Cycle




Process execution consists of a cycle of CPU execution and I/O request Process execution begins with a CPU burst and followed by an I/O burst

CPU Scheduler


Whenever the CPU becomes idle, the OS must select one of the processes in the ready queue to be executed The selection process is carried out by the short-term scheduler

Diagram of Process State

Preemptive scheduling vs. non-preemptive scheduling


CPU scheduling decisions may take place when a process: 1. 2. 3. 4. Switches from running to waiting state Terminates Switches from waiting to ready Switches from running to ready state

Preemptive scheduling vs. non-preemptive scheduling




When scheduling takes place only under circumstances 1 and 2, we say that the scheduling scheme is non-preemptive; otherwise, its called preemptive Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keep the CPU until it release the CPU either by terminating or by switching to waiting state. (Windows 95 and earlier)

Preemptive scheduling vs. non-preemptive scheduling




Preemptive scheduling incurs a cost associated with access to share data. Consider the case of two processes that share a data. It is preemptive so that while one process is updating the data, the second process then tries to read the data, which are in an inconsistent state. (Ch6)

Dispatcher


Dispatcher module gives control of the CPU to the process selected by the short-term scheduler It should work as fast as possible, since it is invoked during every process switch Dispatch latency time it takes for the dispatcher to stop one process and start another running

Scheduling Criteria
CPU utilization keep the CPU as busy as possible (from 0% to 100%) Throughput # of processes that complete their execution per time unit amount of time to execute a particular Process

Turnaround time

Waiting time

amount of time a process has been waiting in the ready queue

Response time amount of time it takes from when a request was submitted until the first response is produced

Optimization Criteria
    

Max CPU utilization Max throughput Min turnaround time Min waiting time Min Response time

Scheduling Algorithems
     

First Come First Serve Scheduling Shortest Job First Scheduling Priority Scheduling Round-Robin Scheduling Multilevel Queue Scheduling Multilevel Feedback-Queue Scheduling

First Come First Serve Scheduling (FCFS)


Process Burst time
P1 P2 P2 24 3 3

First Come First Serve Scheduling




The average of waiting time in this policy is usually quite long Waiting time for P1=0; P2=24; P3=27 Average waiting time= (0+24+27)/3=17

 

First Come First Serve Scheduling




Suppose we change the order of arriving job P2, P3, P1

First Come First Serve Scheduling




Consider if we have a CPU-bound process and many I/O-bound processes There is a convoy effect as all the other processes waiting for one of the big process to get off the CPU FCFS scheduling algorithm is non-preemptive

Short job first scheduling (SJF)




This algorithm associates with each process the length of the processes next CPU burst If there is a tie, FCFS is used In other words, this algorithm can be also regard as shortest-next-cpu-burst algorithm

 

Short job first scheduling




SJF is optimal gives minimum average waiting time for a given set of processes

Example
Processes Burst time
P1 P2 P3 P4 6 8 7 3

FCFS average waiting time: (0+6+14+21)/4=10.25 SJF average waiting time: (3+16+9+0)/4=7

Short job first scheduling


Two schemes: Non-preemptive once CPU given to the process it cannot be preempted until completes its CPU burst Preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-RemainingTime-First (SRTF)

Short job first schedulingNon-preemptive

Short job first schedulingPreemptive

Priority Scheduling
A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority)  Preemptive  Non-preemptive SJF is a special priority scheduling where priority is the predicted next CPU burst time, so that it can decide the priority

Priority Scheduling
Processes Burst time Priority Arrival time P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 The average waiting time=(6+0+16+18+1)/5=8.2

Priority Scheduling
Processes Burst time Priority Arrival time P1 10 3 0.0 P2 1 1 1.0 P3 2 4 2.0 P4 1 5 3.0 P5 5 2 4.0

Gantt chart for both preemptive and nonpreemptive, also waiting time

Priority Scheduling
Problem : Starvation low priority processes may never execute Solution : Aging as time progresses increase the priority of the process

Round-Robin Scheduling


The Round-Robin is designed especially for time sharing systems. It is similar FCFS but add preemption concept A small unit of time, called time quantum, is defined

Round-Robin Scheduling


Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.

Round-Robin Scheduling

Round-Robin Scheduling


If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.

Round-Robin Scheduling
Performance  q large => FIFO  q small => q must be large with respect to context switch, otherwise overhead is too high


Typically, higher average turnaround than SJF, but better response

Round-Robin Scheduling

You might also like