0% found this document useful (0 votes)
11 views26 pages

Module3-CCS 2203-Operating Systems(Part 3)

This document discusses various preemptive CPU scheduling algorithms including Preemptive Priority, Shortest Remaining Time First (SRTF), and Round Robin (RR). It explains key concepts such as arrival time, completion time, waiting time, burst time, and turnaround time, along with formulas for calculating average waiting and turnaround times. Additionally, it covers the impact of overhead in scheduling and provides examples illustrating the application of these algorithms.

Uploaded by

zennn
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)
11 views26 pages

Module3-CCS 2203-Operating Systems(Part 3)

This document discusses various preemptive CPU scheduling algorithms including Preemptive Priority, Shortest Remaining Time First (SRTF), and Round Robin (RR). It explains key concepts such as arrival time, completion time, waiting time, burst time, and turnaround time, along with formulas for calculating average waiting and turnaround times. Additionally, it covers the impact of overhead in scheduling and provides examples illustrating the application of these algorithms.

Uploaded by

zennn
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/ 26

CCS 2203

OPERATING SYSTEMS
Module 3 – Process Management (Part 3)
DIFFERENT TYPES OF PREEMPTIVE CPU
SCHEDULING

1. Preemptive Priority (PPrio)


2. Shortest Remaining Time First (SRTF)
3. Round Robin (RR)
4. Round Robin with Overhead (RRO)
DIFFERENT TIME WITH RESPECT TO A PROCESS
• Arrival Time: Time at which the process arrives in the ready
queue.
• Completion Time or End Time or Finish Time: Time at which
process completes its execution.
• Waiting time – amount of time a process has been waiting in the
ready queue
• Burst Time is the time the CPU taking control of the process.
• AWT or Average waiting time is the average of the waiting times of
the processes in the queue, waiting for the scheduler to pick them
for execution.
• For Non preemptive Algos = S.T – A.T
• For Preemptive Algos = E.T – A.T – B.T
• Turnaround time – amount of time to execute a particular
process.
- It can also be considered as the sum of the time periods spent
waiting to get into memory or ready queue, execution on CPU and
executing input/output.
• Finish/End Time – Arrival Time
PREEMPTIVE CPU SCHEDULING
ALGORITHMS
PREEMPTIVE SCHEDULING
• It is used when a process switches from running
state to ready state or from waiting state to ready
state.

• The resources (mainly CPU cycles) are allocated


to the process for the limited amount of time and
then is taken away, and the process is again
placed back in the ready queue if that process
still has CPU burst time remaining.

• That process stays in ready queue till it gets next


chance to execute.
PREEMPTIVE SCHEDULING
Steps:
1. Arrival Time
2. Compare (SRTF / Priority)
3. Execute Burst Time
SHORTEST REMAINING TIME FIRST (SRTF)

 Out of all the available processes, CPU is assigned to


the process having smallest burst time.

 SJF Scheduling can be used in both preemptive and


non-preemptive mode.

Preemptive mode of Shortest Job First is called as


Shortest Remaining Time First (SRTF).
SHORTEST REMAINING TIME FIRST (SRTF)
Example #1

16

Time 4: Compare P4, P2, P3 and P5


Remaining Burst:
P4 = 5 P2 = 2 P1 = 0 P2 = 0 P3 = 0 P5 = 0 P4 = 0
SHORTEST REMAINING TIME FIRST (SRTF)
Example #1
Gantt Chart:
16

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 4 – 3 = 1 P1 = 1 – 1 = 0
P2 = 6 – 1 = 5 P2 = 5 – 4 = 1
P3 = 8 – 4 = 4 P3 = 4 – 2 = 2
P4 = 16 – 0 = 16 P4 = 16 – 6 = 10
P5 = 11 – 2 = 9 P5 = 9 – 3 = 6

Average Turnaround Time: Average Waiting Time:


ATT = (1 + 5 + 4 + 16 + 9) / 5 AWT = (0 + 1 + 2 + 10 + 6) / 5
ATT = 7 AWT = 3.8
SHORTEST REMAINING TIME FIRST (SRTF)
Example #2

Time 4: Compare P1, P2, P3 and P5


Remaining Burst:
P1 = 6 P2 = 4 P3 = 2 P4 = 0 P3 = 0 P6 = 0 P5 = 0 P2 = 0 P1 = 0
SHORTEST REMAINING TIME FIRST (SRTF)
Example #2
Gantt Chart:

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 19 – 0 = 19 P1 = 19 – 7 = 12
P2 = 13 – 1 = 12 P2 = 12 – 5 = 7
P3 = 6 – 2 = 4 P3 = 4 – 3 = 1
P4 = 4 – 3 = 1 P4 = 1 – 1 = 0
P5 = 9 – 4 = 5 P5 = 5 – 2 = 3
P6 = 7 – 5 = 2 P6 = 2 – 1 = 1

Average Turnaround Time: Average Waiting Time:


ATT = (19 + 12 + 4 + 1 + 5 + 2) / 6 AWT = (12 + 7 + 1 + 0 + 3 + 1) / 6
ATT = 7.17 AWT = 4
PREEMPTIVE PRIORITY (PPRIO) Example #1
Note: Priority = Highest number represents higher priority

Remaining Burst: Time 10: Compare priority of P1 and P2

P1 = 3 P2 = 2 P3 = 0 P4 = 0 P5 = 0 P2 = 0 P1 = 0
PREEMPTIVE PRIORITY (PPRIO)
Example #1
Gantt Chart:

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 15 – 0 = 15 P1 = 15 – 4 = 11
P2 = 12 – 1 = 11 P2 = 11 – 3 = 8
P3 = 3 – 2 = 1 P3 = 1 – 1 = 0
P4 = 8 – 3 = 5 P4 = 5 – 5 = 0
P5 = 10 – 4 = 6 P5 = 6 – 2 = 4

Average Turnaround Time: Average Waiting Time:


ATT = (15 + 11 + 1 + 5 + 6) / 5 AWT = (11 + 8 + 0 + 0 + 4) / 5
ATT = 7.6 AWT = 4.6
PREEMPTIVE PRIORITY (PPRIO) Example #2

Process Id Arrival Time Burst Time Priority (H)


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

1 3 6 7 11 15 16 19
P4 P5 P4 P2
Time 6: Compare prio of P1, P2 and P4
Remaining Burst: Time 11: Compare prio of P1, P2 and P4
P1 = 3 P2 = 1 P3 = 0 P4 = 4 P5 = 0 P4 = 0 P2 = 0 P1 = 0
PREEMPTIVE PRIORITY (PPRIO)
Example #2
Gantt Chart:

1 3 6 7 11 15 16 19
P4 P5 P4 P2

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 19 – 0 = 19 P1 = 19 – 4 = 15
P2 = 16 – 1 = 15 P2 = 15 – 3 = 12
P3 = 6 – 3 = 3 P3 = 3 – 3 = 0
P4 = 15 – 6 = 9 P4 = 9 – 5 = 4
P5 = 11 – 7 = 4 P5 = 4 – 4 = 0

Average Turnaround Time: Average Waiting Time:


ATT = (19 + 15 + 3 + 9 + 4) / 5 AWT = (15 + 12 + 0 + 4 + 0) / 5
ATT = 10 AWT = 6.2
ROUND ROBIN (RR) Example #1

Time Quantum = 2

P4 P5 P1 P2 P5 P1

Remaining Burst:
P1 = 3 P2 = 1 P3 = 0 P4 = 0 P5 = 1 P1 = 1 P2 = 0 P5 = 0 P1 = 0
ROUND ROBIN (RR)
Example #1
Gantt Chart:

P4 P5 P1 P2 P5 P1

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 14 – 0 = 14 P1 = 14 – 5 = 9
P2 = 12 – 1 = 11 P2 = 11 – 3 = 8
P3 = 5 – 2 = 3 P3 = 3 – 1 = 2
P4 = 7 – 3 = 4 P4 = 4 – 2 = 2
P5 = 13 – 4 = 9 P5 = 9 – 3 = 6

Average Turnaround Time: Average Waiting Time:


ATT = (14 + 11 + 3 + 4 + 9) / 5 AWT = (9 + 8 + 2 + 2 + 6) / 5
ATT = 8.2 AWT = 5.4
ROUND ROBIN (RR) Example #2

Process Id Arrival Time Burst Time


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

Time Quantum = 3

3 6 9 12 14 15 17

P4 P5 P1 P4
Remaining Burst:
P1 = 1 P2 = 0 P3 = 0 P4 = 2 P5 = 0 P1 = 0 P4 = 0
ROUND ROBIN (RR)
Example #2
Gantt Chart:

3 6 9 12 14 15 17

P4 P5 P1 P4

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 15 – 0 = 15 P1 = 15 – 4 = 11
P2 = 6 – 1 = 5 P2 = 5 – 3 = 2
P3 = 9 – 3 = 6 P3 = 6 – 3 = 3
P4 = 17 – 6 = 11 P4 = 11 – 5 = 6
P5 = 14 – 7 = 7 P5 = 7 – 2 = 5

Average Turnaround Time: Average Waiting Time:


ATT = (15 + 5 + 6 + 11 + 7) / 5 AWT = (11 + 2 + 3 + 6 + 5) / 5
ATT = 8.8 AWT = 5.4
OVERHEAD
 The amount of processing time used by system
software such as the operating system, database
manager or network protocols.

 In communications, the additional codes


transmitted for control and error checking, which
take time to process.
If the CPU scheduling policy is FCFS and there is 1
unit of overhead in scheduling the processes, find
the efficiency of the algorithm.
δ denotes the context switching overhead.
 Useless Time / Wasted time
= 6 x δ = 6 x 1 = 6 unit
 Total time = 23 unit

 Useful time = 23 unit – 6 unit = 17 unit

Compute for Efficiency ( η )


 Useful time / Total time
 17 unit / 23 unit = 0.7391 x 100

 73.91%
ROUND ROBIN WITH OVERHEAD (RRO)
Process B.T AT 1st 2nd 3rd
round round round
P1 6 0 2 0 0
P2 5 0 1 0 0
P3 7 2 3 0 0
P4 12 3 8 4 0
P5 8 3 4 0 0

Time Quantum = 4 and Overhead Time = 1 Time unit


P1 (4) P2 (4) P3 (4) P4 (4) P5 (4)

0 4 5 9 10 14 15 19 20 24 25

P1 (2) P2 (1) P3 (3) P4 (4) P5 (4) P4 (4)

25 27 28 29 30 33 34 38 39 43 44 48
ROUND ROBIN (RRO)
Gantt Chart:

P1 (4) P2 (4) P3 (4) P4 (4) P5 (4)

0 4 5 9 10 14 15 19 20 24 25

P1 (2) P2 (1) P3 (3) P4 (4) P5 (4) P4 (4)


25 27 28 29 30 33 34 38 39 43 44 48

Turnaround Time Waiting Time


Formula: Other Formula:
End Time – Arrival Time Turnaround Time – Burst Time
P1 = 27 – 0 = 27 P1 = 27 – 6 = 21
P2 = 29 – 0 = 29 P2 = 29 – 5 = 24
P3 = 33 – 2 = 31 P3 = 31 – 7 = 24
P4 = 48 – 3 = 45 P4 = 45 – 12 = 33
P5 = 43 – 3 = 40 P5 = 40 – 8 = 32

Average Turnaround Time: Average Waiting Time:


ATT = (27 + 29 + 31 + 45 + 40) / 5 AWT = (21 + 24 + 24 + 33 + 32) / 5
ATT = 34.4 AWT = 26.8
ROUND ROBIN (RRO) - EFFICIENCY
P1 (4) P2 (4) P3 (4) P4 (4) P5 (4)
0 4 5 9 10 14 15 19 20 24 25

P1 (2) P2 (1) P3 (3) P4 (4) P5 (4) P4 (4)

25 27 28 29 30 33 34 38 39 43 44 48

δ denotes the context switching overhead.


 Useless Time / Wasted time
= 10 x δ = 10 x 1 = 10 unit
 Total time = 48 unit
 Useful time = 48 unit – 10 unit = 38 unit

Compute for Efficiency ( η)


 Useful time / Total time
 38 unit / 48 unit = 0.791 x 100
 79.17%
END OF MODULE 3 – PART 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy