Operating System CSET209: Cpu Scheduling Algorithms
Operating System CSET209: Cpu Scheduling Algorithms
CSET209
Characteristics:
This algorithm is applied where short jobs are needed to be given preference.
Each process gets the CPU for this fixed time quantum during which it executes and after that it is
preempted and added to the end of ready queue. Timer interrupts every quantum to schedule next
process.
Lets say there are n processes in ready queue and time quantum is q time units,
Each process gets 1/n x (CPU time) in chunks of at most q time units at a time.
No process has to wait for more than (n-1)q time (considering no context switch time)
Slide 19
VM2 In our next topic we see an algortihm which is expecially designed for multi-tasking operating systems. The
name is round robin
Vivek Mehta, 2/5/2023
VM5
ROUND ROBIN SCHEDULING
Implementation:
If the CPU burst of the currently running process is longer than 1 time quantum, a context
switch will be executed and the current process will be put at the tail of the ready queue.
The CPU scheduler will then select the next process from the ready queue.
Slide 20
VM5 In our next topic we see an algortihm which is expecially designed for multi-tasking operating systems. The
name is round robin
Vivek Mehta, 2/5/2023
ROUND ROBIN SCHEDULING
Time Quantum =20
Waiting time
Assume arrival time = 0 for all process
P1 = 57+24 = 81
Neglect context switch time for simplicity
From t=20 to t =77
Process Burst Time From t=97 to t=121
P1 53 P2 = 20
P2 17
from t=0 to t =20
P3 68
P3 = 37+40+17 = 97
P4 24
Form t=0 to t 37
From t=57 to t =97
From t =117 to t =134
P4 = 57+40 = 97
From t=0 to t = 57
From t=77 to t=117
Avg waiting time: (81 + 20 + 94 + 97)/4 = 73
ROUND ROBIN SCHEDULING
Advantages: No starvation, fair time and resource sharing, and good response time
Disadvantages: High avg turnaround time than SRTF, does not consider priority.
Performance:
If q is small, overhead is too high and inefficient CPU utilization (q must be large than
context switch time).
Consider the set of 5 processes whose arrival time and burst time are given below-
Process Id Arrival time Burst time
P1 0 5
P2 1 3
P3 2 1
P4 3 2
P5 4 3
If the CPU scheduling policy is Round Robin with a time quantum of 2 units, calculate
the average waiting time and average turnaround time.
Round Robin Scheduling
ROUND ROBIN SCHEDULING: SAMPLE PROBLEM
P1 13 13 – 0 = 13 13 – 5 = 8
P2 12 12 – 1 = 11 11 – 3 = 8
P3 5 5–2=3 3–1=2
P4 9 9–3=6 6–2=4
P5 14 14 – 4 = 10 10 – 3 = 7