0% found this document useful (0 votes)
36 views14 pages

Priority Scheduling in Operating Systems

The document discusses various CPU scheduling algorithms, specifically focusing on Priority Scheduling (both preemptive and non-preemptive) and Round Robin (RR) scheduling. It includes examples with Gantt charts and calculations for turnaround and waiting times for different processes. The document also highlights the advantages and disadvantages of these scheduling methods, such as starvation in priority scheduling and the implementation of time quantum in RR scheduling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views14 pages

Priority Scheduling in Operating Systems

The document discusses various CPU scheduling algorithms, specifically focusing on Priority Scheduling (both preemptive and non-preemptive) and Round Robin (RR) scheduling. It includes examples with Gantt charts and calculations for turnaround and waiting times for different processes. The document also highlights the advantages and disadvantages of these scheduling methods, such as starvation in priority scheduling and the implementation of time quantum in RR scheduling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Operating System

Dr. Akhtar Husain


Associate Professor in Department of CSIT,
Faculty of Engineering and Technology,
MJP Rohilkhand University, Bareilly, U.P., India.
Mobile : 9457381048, 9319760019
Email: akhtarhusain@mjpru.ac.in
Priority
Scheduling
 In this scheduling a priority i.e., an integer value is assigned to
each process

 CPU is allocated to a process having highest priority

 Priority scheduling may be of two type

1. Preemptive
2. Nonpreemptive

Disadvantge
Starvation or indefinite blocking– low priority processes
may never execute

Solution is Aging – Each time a process is selected for execution,


increase the priority by one of each process

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Non-Preemptive Priority
Scheduling
Question 1

Process Arrival Time(ms) Priority Burst Time(ms)


P1 0 3 5
P2 0 1 1
P3 0 2 2
P4 0 5 5
P5 0 7 5

Case 1: Highest priority is represented by largest number

Gantt Chart
P5 P4 P1 P3 P2

0 5 10 15
Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems
17 18
Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Calculations
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 15 15 10

P2 1 0 18 18 17

P3 2 0 17 17 15

P4 5 0 10 10 5

P5 5 0 5 5 0

Average =(15+18+17+10+5)/5 =(10+17+15+5+0)/5


= 65/5=13 ms =47/5=9.4 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Case 2: Highest priority is represented by lowest number
Gantt Chart
P2 P3 P1 P4 P5

0 1 3 8 13 18

Calculations
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 8 8 3
P2 1 0 1 1 0

P3 2 0 3 3 1
P4 5 0 13 13 8
P5 5 0 18 18 13
Average =(8+1+3+13+18)/5 =(3+0+1+8+13)/5
= 43/5=8.6 ms =25/5=5 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Question 2 : When processes
enter in ready queue at
different times.

Process Arrival Time(ms) Priority Burst Time(ms)


P1 0 3
5
P2 1 1
1
P3 2 2
2
P4 3 5
5
P5 4
Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems
7
5 Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Case 1: Non-preemptive and Highest priority is represented by largest number

Gantt Chart
P1 P5 P4 P3 P2

0 5 10 15 17 18
Calculations
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 5 5 0
P2 1 1 18 17 16

P3 2 2 17 15 13
P4 5 3 15 12 7
P5 5 4 10 6 1
Average =(5+17+15+12+6)/5 =(0+16+13+7+1)/5
= 55/5=11 ms =37/5=7.4 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Case 2: Non-preemptive and Highest priority is represented by lowest number

Gantt Chart
P1 P2 P3 P4 P5

0 5 6 8 13 18

Calculations
Process Burst Time (BT) Arrival Time Completion Time Turn Around Time Waiting Time
Number ms (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 5 5 0
P2 1 1 6 5 4

P3 2 2 8 6 4
P4 5 3 13 10 5
P5 5 4 18 14 9
Average =(5+5+6+10+14)/5 =(0+4+4+5+9)/5
= 40/5=8 ms =22/5=4.4 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Case 3: preemptive and Highest priority is represented by largest number.
Gantt Chart
P1 P1 P1 P4 P5 P4 P1 P3 P2

0 1 2 3 4 9 13 15 17 18

Calculations
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 15 15 10
P2 1 1 18 17 16

P3 2 2 17 15 13
P4 5 3 13 10 5
P5 5 4 9 5 0
Average =(15+17+15+10+5)/5 =(10+16+13+5+0)/5
= 62/5=12.4ms =44/5= 8.8ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Case 4: preemptive and Highest priority is represented by smallest number

Gantt Chart
P1 P2 P3 P3 P1 P4 P5

0 1 2 3 4 8 13 1

Calculations
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 8 8 3

P2 1 1 2 1 0

P3 2 2 4 2 0

P4 5 3 13 10 5

P5 5 4 18 14 9

Average =(8+1+2+10+14)/5 =(3+0+0+5+9)/5


= 35/5=7 ms =17/5= 3.4 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Round Robin (RR) CPU
Scheduling
 RR scheduling specially used in time sharing systems
 RR = FCFS+preemption after a time quantum or time slice
 Where time quantum is small unit of time
 Ready queue is circular queue

Implementation:
 Ready queue is implemented as a FIFO queue of processes
 New processes are added to the Tail of the ready queue
 The CPU scheduler selects the first process from the ready
queue, fix a timer to stop after 1 time quantum and dispatches
the process.
 After time slice has elapsed, the process is preempted and
added to the end of the ready queue.
 If there are N processes in the ready queue and the time
quantum is t, then each process gets 1/N of the CPU time in
chunks of at most t time units at once. No process waits
more than [(N-1) * t ] time units.

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Time Quantum and Number of Context
Switches

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
RR Numerical Question
Case 1: Time quantum t=3 ms
Gantt Chart :
P1 P2 P3 P4 P5 P1 P4 P5

0 3 4 6 9 12 14 16 18

Calculation
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 14 14 9
P2 1 0 4 4 3

P3 2 0 6 6 4
P4 5 0 16 16 11
P5 5 0 18 18 13
Average =(14+4+6+16+18)/5 =(9+3+4+11+13)/5
= 58/5=11.6 ms =40/5= 8 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Case 2: Time quantum t=1 ms

Gantt Chart:
P1 P2 P3 P4 P5 P1 P3 P4 P5 P1 P4 P5 P1 P4 P5 P1 P4 P5

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Calculation:
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 16 16 11
P2 1 0 2 2 1

P3 2 0 7 7 5
P4 5 0 17 17 12
P5 5 0 18 18 13
Average =(16+2+7+17+18)/5 =(11+1+5+12+13)/5
= 60/5=12 ms =42/5= 8.4 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education

You might also like