0% found this document useful (0 votes)
12 views7 pages

Priority&Round Robin Algorithm

The document discusses nonpreemptive priority scheduling and round robin scheduling algorithms, providing examples with calculations for waiting time, turn-around time, and throughput. It includes Gantt charts and formulas for average waiting time (AWT) and average turn-around time (ATAT) for different sets of processes. Additionally, it outlines the types of CPU scheduling algorithms, distinguishing between nonpreemptive and preemptive methods.

Uploaded by

ahmed.waasel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Priority&Round Robin Algorithm

The document discusses nonpreemptive priority scheduling and round robin scheduling algorithms, providing examples with calculations for waiting time, turn-around time, and throughput. It includes Gantt charts and formulas for average waiting time (AWT) and average turn-around time (ATAT) for different sets of processes. Additionally, it outlines the types of CPU scheduling algorithms, distinguishing between nonpreemptive and preemptive methods.

Uploaded by

ahmed.waasel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

4- Priority Scheduling [nonpreemptive]

Example1:Consider the following set of processes with their Burst time and
arrival time,
• Draw the Gantt charts for the (Priority) algorithm.
• Calculate the waiting time for each process and AWT?
• Calculate the turn-around time for each algorithm
process and ATAT?
• Calculate the Throughput?
process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling chart

Average waiting time(AWT) = (w(p2) + w(p5) + w(p1) + w(p3)+w(p4)) / n


Now we will calculate waiting time for each process:
w(p)=Start_time - Arrival time.
1. w(p2)=(0-0)=0
2. w(p5)=(1-0)=1
3. w(p1)=(6-0)=6
4. w(p3)=(16-0)=16
5. w(p4)=(18-0)=18
Average waiting time (AWT) = (0 + 1 + 6 + 16+18) / 5 = 8.2 msec.
Average turn-around time(ATAT) = (tat(p2) + tat(p5) + tat(p1) + tat(p3)+tat(p4)) / n
Now we will calculate turn-around time for each process:
tat(p)=Burst Time + Wait time.
1. tat(p2)=(1+0)=1
2. tat(p5)=(5+1)=6
3. tat(p1)=(10+6)=16
4. tat(p3)=(2+16)=18
5. tat(p4)=(1+18)=19
Average turn-around time (ATAT) = (1 + 6 + 16 + 18+19) / 5 = 12 msec.
Throughput=n/length_cycle
Throughput =5/(10+1+2+1+5)=0.263
4- Priority Scheduling [nonpreemptive]
Example2:Consider the following set of processes with their Burst time and
arrival time,
• Draw the Gantt charts for the (Priority) algorithm.
• Calculate the waiting time for each process and AWT?
• Calculate the turn-around time for each algorithm
process and ATAT?
• Calculate the Throughput?
process Arrival Time Burst Time Priority
P0 3 5 1
P1 2 6 2
P2 4 7 1
P3 1 3 2
Priority scheduling chart
P3 P0 P2 P1
1 4 9 16 22
Average waiting time(AWT) = (w(p3) + w(p0) + w(p2) + w(p1)) / n
Now we will calculate waiting time for each process:
w(p)=Start_time - Arrival time.
6. w(p3)=(1-1)=0
7. w(p0)=(4-3)=1
8. w(p2)=(9-4)=5
9. w(p1)=(16-2)=14
Average waiting time (AWT) = (0 + 1 + 5 + 14) / 4 = 5 msec.
Average turn-around time(ATAT) = (tat(p3) + tat(p0) + tat(p2) + tat(p1)) / n
Now we will calculate turn-around time for each process:
tat(p)=Burst Time + Wait time.
6. tat(p3)=(3+0)=3
7. tat(p0)=(5+1)=6
8. tat(p2)=(7+5)=12
9. tat(p1)=(6+14)=20
Average turn-around time (ATAT) = (3 + 6 + 12 + 20) / 4 = 10.25 msec.
Throughput=n/length_cycle
Throughput =4/(5+6+7+3)=0.19
Source code of Priority Scheduling [nonpreemptive]
5-Round Robin (RR)
Example1: Consider the following set of processes with their Burst time and
arrival time, and Time Quantum = 4
• Draw the Gantt charts for the (RR) algorithm.
• Calculate the waiting time for each process and AWT?
• Calculate the turn-around time for each process and ATAT?
• Calculate the Throughput?

process Burst Time


P1 24
P2 3
P3 3
RR scheduling chart
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Average waiting time(AWT) = (w(p1) + w(p2) + w(p3) ) / n


Now we will calculate waiting time for each process:
w(p)=Start_time - Arrival time. ,
w(p)= start_time(new process)-leave time(same process for last execution)
1. w(p1)=(0-0)+ (10-4) =(0+6)=6
2. w(p2)=(4-0)=4
3. w(p3)=(7-0)=7
Average waiting time (AWT) = (6+4+7) / 3 = 5.67 msec.

Average turn-around time(ATAT) = (tat(p1) + tat(p2) + tat(p3) ) / n


Now we will calculate turn-around time for each process:
tat(p)=Burst Time + Wait time.
1. tat(p1)=(24+6)=30
2. tat(p2)=(3+4)=7
3. tat(p3)=(3+7)=10
Average turn-around time (ATAT) = (30+7+10) / 3 = 15.67 mesic.

Throughput=n/length_cycle
Throughput =3/(24+3+3)=0.1
5-Round Robin (RR)
Example2:Consider the following set of processes with their Burst time and
arrival time, and Time Quantum = 3
• Draw the Gantt charts for the (RR) algorithm.
• Calculate the waiting time for each process and AWT?
• Calculate the turn-around time for each process and ATAT?
• Calculate the Throughput?

process Arrival Time Burst Time


P1 0 10
P2 1 4
P3 2 5
P4 3 3
RR scheduling chart
P1 P2 P3 P4 P1 P2 P3 P1 P1
0 3 6 9 12 15 16 18 21 22
Average waiting time(AWT) = (w(p1) + w(p2) + w(p3) +w(p4)) / n
Now we will calculate waiting time for each process:
4. w(p1)=(0-0)+ (12-3)+(18-15) =(0+9+3)=12
5. w(p2)=(3-1)+(15-6)=(2+9)=11
6. w(p3)=(6-2)+(16-9)=(4+7)=11
7. w(p4)=(9-3)=6
Average waiting time (AWT) = (12+11+11+6) / 4 = 10 msec.

Average turn-around time(ATAT) = (tat(p1) + tat(p2) + tat(p3) ) / n


Now we will calculate turn-around time for each process:
4. tat(p1)=(10+12)=22
5. tat(p2)=(4+11)=15
6. tat(p3)=(5+11)=16
7. tat(p3)=(3+6)=9
Average turn-around time (ATAT) = (22+15+16+9) / 4 = 15.5 mesic.

Throughput=n/length_cycle
Throughput =4/(10+4+5+3)=0.18
Types of CPU scheduling algorithms

nonpreemptive preemptive

FCFS RR

SJF SRTF

Priority Priority

You might also like