Exercise Ms.Reema alOraini CPU SCHEDULING Exercise Ms.Reema alOraini
Burst Time (millisecond) Question 1 Consider the following set of processes: Draw the Gantt Chart that illustrates the execution of these processes using preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer P1
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 1 P1
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 P2 had higher priority so it will be execution Timer 2 P1 P2 2
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 At time 3 p2 is finished with execution Timer 3 P1 P2 2 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 So p1 will be continue execution Timer 3 P1 P2 P1 2 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 4 P1 P2 P1 2 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 5 P1 P2 P1 2 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 6 P1 P2 P1 2 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 At time 7 p1 is finished with execution And p3 does not arrive yet Timer 7 P1 P2 P1 2 7 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 P3 is arrive so it will be execution Timer 8 P1 P2 P1 P3 8 2 7 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 9 P1 P2 P1 P3 8 2 7 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 At time 10 p3 is finished with execution Timer 10 P1 P2 P1 P3 8 2 7 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 P3 8 5 TAT for p1 = 7-0=7 P1 P2 P1 P3 2 7 8 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 7 P2 2 3 P3 8 5 TAT for p2 = 3-2=1 P1 P2 P1 P3 2 7 8 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 7 P2 2 3 P3 8 5 TAT for p3 = 10-8=2 P1 P2 P1 P3 2 7 8 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 7 P2 2 3 P3 8 5 WT for p1=7-6=1 P1 P2 P1 P3 2 7 8 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 7 P2 2 3 P3 8 5 WT for p2=1-1=0 P1 P2 P1 P3 2 7 8 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 7 P2 2 3 P3 8 5 WT for p3=2-2=0 P1 P2 P1 P3 2 7 8 10 3
preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 7 P2 2 3 P3 8 5 P1 P2 P1 P3 Average TAT=(7+1+2)/3=3.3 Average WT=(1+0+0)/3=0.33 2 7 8 10 3
Burst Time (millisecond) Question 1 Consider the following set of processes: Draw the Gantt Chart that illustrates the execution of these processes using NON- preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer P1
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 1 P1
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 2 P1
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 3 P1
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 4 P1
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 5 P1
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer At time 6 p1 finished execution 6 P1 P2 6
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer At time 7 p2 finished execution 7 P1 P2 6 7
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer At time 8 p3 will be execution 8 P1 P2 6 7 8
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 9 P1 P2 p3 6 7 8
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority P1 6 1 P2 2 3 P3 8 5 Timer 10 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 P3 8 5 TAT for p1 = 6-0=6 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 P3 8 5 TAT for p2 = 7-2=5 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 5 P3 8 TAT for p3 = 10-8=2 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 5 P3 8 WT for p1 = 6-6=0 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 5 P3 8 WT for p2= 5-1=4 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 5 4 P3 8 WT for p3=2-2=0 P1 P2 p3 6 7 8 10
Non-preemptive Priority algorithm Processes Arrival time Burst Time (millisecond) Priority Turnaround time Waiting time P1 6 1 P2 2 3 5 4 P3 8 Average TAT=(6+5+2)/3=4.33 Average WT=(0+4+0)/3=1.33 P1 P2 p3 6 7 8 10
D. For the given set of processes , which algorithm is better? Why? Non-preemptive Priority algorithm preemptive Priority algorithm Average TAT=(6+5+2)/3=4.33 Average WT=(0+4+0)/3=1.33 Average TAT=(7+1+2)/3=3.3 Average WT=(1+0+0)/3=0.33 By Comparing Waiting Time and Turnaround Time So , the Preemptive algorithm is better
Burst Time (millisecond) Question 2 Consider the following set of processes: Draw the Gantt Chart that illustrates the execution of these processes using Round-Robin algorithm where time quantum=5 millisecond. Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3
Round-Robin algorithm where time quantum=5 millisecond. Timer Queue : p1 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
Round-Robin algorithm where time quantum=5 millisecond. Timer 1 Queue : p1 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
Round-Robin algorithm where time quantum=5 millisecond. Timer 2 Queue : p1 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
Round-Robin algorithm where time quantum=5 millisecond. Timer 3 Queue : P1 p2 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
Round-Robin algorithm where time quantum=5 millisecond. Timer 4 Queue : P1 p2 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
Round-Robin algorithm where time quantum=5 millisecond. Timer 5 Queue : P1 P2 p1 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1 5
Round-Robin algorithm where time quantum=5 millisecond. Timer 6 Queue : P1 P2 p3 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 6-5=1 P1 P2 5 6
Round-Robin algorithm where time quantum=5 millisecond. Timer 7 Queue : P1 P2 p3 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 6-5=1 P1 P2 P1 5 7 6
Round-Robin algorithm where time quantum=5 millisecond. Timer 8 Queue : P1 P2 p3 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 6-5=1 P1 P2 P1 P3 5 6 7
Round-Robin algorithm where time quantum=5 millisecond. Timer 9 Queue : P1 P2 p3 Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 6-5=1 P1 P2 P1 P3 5 6 7 9
Round-Robin algorithm where time quantum=5 millisecond. Processes Arrival time Burst Time (millisecond) Waiting Time P1 6 P2 2 1 P3 WT for p1=(0-0)+(6-5)=1 P1 P2 P1 P3 5 6 7 9
Round-Robin algorithm where time quantum=5 millisecond. Processes Arrival time Burst Time (millisecond) Waiting Time P1 6 1 P2 2 P3 WT for p2=(5-2)=3 P1 P2 P1 P3 5 6 7 9
Round-Robin algorithm where time quantum=5 millisecond. Processes Arrival time Burst Time (millisecond) Waiting Time P1 6 1 P2 2 3 P3 WT for p3=(7-6)=1 P1 P2 P1 P3 5 6 7 9
Round-Robin algorithm where time quantum=5 millisecond. Processes Arrival time Burst Time (millisecond) Waiting Time P1 6 1 P2 2 3 P3 Average WT =(1+3+1)/3 =1.67 P1 P2 P1 P3 5 6 7 9
Burst Time (millisecond) Draw the Gantt Charts that illustrates the execution of these processes using FCFS algorithm , preemptive SJF and Non- preemptive SJF Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 1 P1
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 2 P1
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 3 P1
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 4 P1
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 5 P1
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 6 P1 P2 6
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 7 P1 P2 6 7
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 8 P1 P2 P3 6 7
The FCFS algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 9 P1 P2 P3 6 7 9
The FCFS algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 P3 P1 P2 P3 WT for p1 =0-0=0 6 7 9
The FCFS algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 P3 P1 P2 P3 WT for p2 =6-2=4 6 7 9
The FCFS algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 4 P3 P1 P2 P3 WT for p3 =7-6=1 6 7 9
The FCFS algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 4 P3 P1 P2 P3 Average WT =(0+4+1)/3=1.67 6 7 9
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 P1
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 1 P1
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 2 P2 shorter than p1 P1 P2 2
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 3 6-2=4 P1 P2 P1 2 3
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 4 6-2=4 P1 P2 P1 2 3
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 5 6-2=4 P1 P2 P1 2 3
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 6 6-2=4 P1 P2 P1 2 3
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 7 6-2=4 P1 P2 P1 P3 2 3 7
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 8 6-2=4 P1 P2 P1 P3 2 3 7
The preemptive SJF (short job first) algorithm Gantt Chat is : Timer Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 9 6-2=4 P1 P2 P1 P3 2 3 7 9
The preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 P3 WT for p1 =(0-0)+(3-2)=1 P1 P2 P1 P3 2 3 7 9
The preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 1 P2 2 P3 WT for p2= 2-2=0 P1 P2 P1 P3 2 3 7 9
The preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 1 P2 2 P3 WT for p3=7-6=1 P1 P2 P1 P3 2 3 7 9
The preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 1 P2 2 P3 Average WT=(1+0+1)/3=0.67 P1 P2 P1 P3 2 3 7 9
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer P1
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 1 P1
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 2 P1
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 3 P1
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 4 P1
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 5 P1
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 6 P2 is shorter than p3 P1 P2 6
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 7 P1 P2 6 7
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 8 P1 P2 P3 6 7
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) P1 6 P2 2 1 P3 Timer 9 P1 P2 P3 6 7 9
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 P3 WT for p1=0-0=0 P1 P2 P3 6 7 9
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 P3 WT for p2=6-2=4 P1 P2 P3 6 7 9
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 4 P3 WT for p3=7-6=1 P1 P2 P3 6 7 9
The Non-preemptive SJF (short job first) algorithm Gantt Chat is : Processes Arrival time Burst Time (millisecond) Waiting time P1 6 P2 2 1 4 P3 Average WT=(0+4+1)/3=1.67 P1 P2 P3 6 7 9
Question 2 cont. D. For the given set of processes and algorithms which algorithm is better? Why? preemptive SJF (short job first) algorithm Non-preemptive SJF (short job first) algorithm FCFS algorithm Average WT =(0+4+1)/3= 1.67 Average WT=(1+0+1)/3=0.67 Average WT=(0+4+1)/3=1.67 By Comparing Waiting Time So , the Preemptive SJF algorithm is better