0% found this document useful (0 votes)
10 views11 pages

? Step-by-Step Execution of Round Robin

The document provides a detailed explanation of the Round Robin scheduling algorithm, including a step-by-step execution example with processes, their arrival and burst times, and the resulting Gantt chart. It also covers the Shortest Remaining Time First (SRTF) scheduling algorithm, highlighting its characteristics, advantages, disadvantages, and a sample execution with metrics. Key performance metrics such as average turnaround time and waiting time are calculated for both algorithms.
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)
10 views11 pages

? Step-by-Step Execution of Round Robin

The document provides a detailed explanation of the Round Robin scheduling algorithm, including a step-by-step execution example with processes, their arrival and burst times, and the resulting Gantt chart. It also covers the Shortest Remaining Time First (SRTF) scheduling algorithm, highlighting its characteristics, advantages, disadvantages, and a sample execution with metrics. Key performance metrics such as average turnaround time and waiting time are calculated for both algorithms.
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/ 11

🔄 Step-by-Step Execution of Round Robin

prepared By Dr Y V RAGHAVARAO PROFESSOR & DEAN


CSE & AI SVR ENGINEERING COLLEGE
🕒 Time Quantum = 5 min
Process Arrival Time Burst Time (Total Time Needed)

P1 (Adam) 0 min 7 min

P2 (Ben) 1 min 4 min

P3 (Charlie) 2 min 15 min

P4 (David) 3 min 11 min

P5 (Eddy) 4 min 20 min

P6 (Frank) 4 min 9 min

✅ Step-by-Step Execution
⏳ At Time = 0 min
🟢 Queue: P1​
🎮 P1 plays for 5 min → Needs 2 more min​
📢 Updated Queue: P2 → P3 → P4 → P5 → P6 → P1
⏳ At Time = 5 min
🟢 Queue: P2 → P3 → P4 → P5 → P6 → P1​
🎮 P2 plays for 4 min → FINISHED ✅​
📢 Updated Queue: P3 → P4 → P5 → P6 → P1
⏳ At Time = 9 min
🟢 Queue: P3 → P4 → P5 → P6 → P1​
🎮 P3 plays for 5 min → Needs 10 more min​
📢 Updated Queue: P4 → P5 → P6 → P1 → P3
⏳ At Time = 14 min
🟢 Queue: P4 → P5 → P6 → P1 → P3​
🎮 P4 plays for 5 min → Needs 6 more min​
📢 Updated Queue: P5 → P6 → P1 → P3 → P4
⏳ At Time = 19 min
🟢 Queue: P5 → P6 → P1 → P3 → P4​
🎮 P5 plays for 5 min → Needs 15 more min​
📢 Updated Queue: P6 → P1 → P3 → P4 → P5
⏳ At Time = 24 min
🟢 Queue: P6 → P1 → P3 → P4 → P5​
🎮 P6 plays for 5 min → Needs 4 more min​
📢 Updated Queue: P1 → P3 → P4 → P5 → P6
⏳ At Time = 29 min
🟢 Queue: P1 → P3 → P4 → P5 → P6​
🎮 P1 plays for 2 min → FINISHED ✅​
📢 Updated Queue: P3 → P4 → P5 → P6
⏳ At Time = 31 min
🟢 Queue: P3 → P4 → P5 → P6​
🎮 P3 plays for 5 min → Needs 5 more min​
📢 Updated Queue: P4 → P5 → P6 → P3
⏳ At Time = 36 min
🟢 Queue: P4 → P5 → P6 → P3​
🎮 P4 plays for 5 min → Needs 1 more min​
📢 Updated Queue: P5 → P6 → P3 → P4
⏳ At Time = 41 min
🟢 Queue: P5 → P6 → P3 → P4​
🎮 P5 plays for 5 min → Needs 10 more min​
📢 Updated Queue: P6 → P3 → P4 → P5
⏳ At Time = 46 min
🟢 Queue: P6 → P3 → P4 → P5​
🎮 P6 plays for 4 min → FINISHED ✅​
📢 Updated Queue: P3 → P4 → P5
⏳ At Time = 50 min
🟢 Queue: P3 → P4 → P5​
🎮 P3 plays for 5 min → FINISHED ✅​
📢 Updated Queue: P4 → P5
⏳ At Time = 55 min
🟢 Queue: P4 → P5​
🎮 P4 plays for 1 min → FINISHED ✅​
📢 Updated Queue: P5
⏳ At Time = 56 min
🟢 Queue: P5​
🎮 P5 plays for 5 min → Needs 5 more min​
📢 Updated Queue: P5
⏳ At Time = 61 min
🟢 Queue: P5​
🎮 P5 plays for 5 min → FINISHED ✅​
🎉 All processes completed at Time = 66 min 🎉
📊 Step-wise Gantt Chart Representation
Scheduling
Round Robin CPU

Time Process Queue After Execution Gantt Chart Update


Executing

0-5 P1 (5 min) P2 → P3 → P4 → P5 → P6 → P1(2 min left) P1

5-9 P2 (4 min) ✅ P3 → P4 → P5 → P6 → P1 P1 → P2

9 - 14 P3 (5 min) P4 → P5 → P6 → P1 → P3(10 min left) P1 → P2 → P3

14 - 19 P4 (5 min) P5 → P6 → P1 → P3 → P4(6 min left) P1 → P2 → P3 → P4

19 - 24 P5 (5 min) P6 → P1 → P3 → P4 → P5(15 min left) P1 → P2 → P3 → P4 → P5

24 - 29 P6 (5 min) P1 → P3 → P4 → P5 → P6(4 min left) P1 → P2 → P3 → P4 → P5 → P6

29 - 31 P1 (2 min) ✅ P3 → P4 → P5 → P6 P1 → P2 → P3 → P4 → P5 → P6 → P1

31 - 36 P3 (5 min) P4 → P5 → P6 → P3(5 min left) P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3

36 - 41 P4 (5 min) P5 → P6 → P3 → P4(1 min left) P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3


→ P4

41 - 46 P5 (5 min) P6 → P3 → P4 → P5(10 min left) P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3


→ P4 → P5
46 - 50 P6 (4 min) ✅ P3 → P4 → P5 P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3
→ P4 → P5 → P6

50 - 55 P3 (5 min) ✅ P4 → P5 P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3
→ P4 → P5 → P6 → P3

55 - 56 P4 (1 min) ✅ P5 P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3
→ P4 → P5 → P6 → P3 → P4

56 - 61 P5 (5 min) P5(5 min left) P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3


→ P4 → P5 → P6 → P3 → P4 → P5

61 - 66 P5 (5 min) ✅ - (All done 🎉) P1 → P2 → P3 → P4 → P5 → P6 → P1 → P3


→ P4 → P5 → P6 → P3 → P4 → P5 → P5

📊 Gantt Chart Timeline:


| P1 | P2 | P3 | P4 | P5 | P6 | P1 | P3 | P4 | P5 | P6 | P3 | P4 | P5 |
|0 5 9 14 19 24 29 31 36 41 46 50 55 61 66|

🖥️ Visual Gantt Chart Representation


📊 Final Results
Process Arrival Time Completion Turnaround Time (TAT) Waiting Time
Time (WT)

P1 0 31 31 - 0 = 31 31 - 7 = 24

P2 1 6 6-1=5 5-4=1

P3 2 50 50 - 2 = 48 48 - 15 = 33

P4 3 56 56 - 3 = 53 53 - 11 = 42

P5 4 66 66 - 4 = 62 62 - 20 = 42

P6 4 46 46 - 4 = 42 42 - 9 = 33

✅ 🎯 Key Takeaways and Final Calculations🔎


Average Turnaround Time (TAT):
31+5+48+53+62+426=2416=∗∗40.16 min∗∗\frac{31 + 5 + 48 + 53 + 62 + 42}{6} = \frac{241}{6}
= **40.16 \text{ min}**631+5+48+53+62+42​=6241​=∗∗40.16 min∗∗

Average Waiting Time (WT):


24+1+33+42+42+336=1756=∗∗29.16 min∗∗\frac{24 + 1 + 33 + 42 + 42 + 33}{6} = \frac{175}{6}
= **29.16 \text{ min}**624+1+33+42+42+33​=6175​=∗∗29.16 min∗∗
Shortest Remaining Time First (SRTF)
Scheduling
1. Introduction
Shortest Remaining Time First (SRTF) is a pre-emptive version of Shortest Job Next (SJN).
In SRTF, the process with the shortest remaining execution time is selected for execution. If
a new process arrives with a shorter remaining time, the current process is pre-empted,
and the new process executes instead.

Key Characteristics:

●​ Preemptive scheduling algorithm.


●​ Prioritizes the process with the shortest remaining burst time.
●​ Can lead to starvation for longer processes if short processes keep arriving.
●​ Ideal for minimizing average waiting time and turnaround time.

2. Example Problem
Example: Consider the following set of processes with their arrival and burst times:

Process Arrival Time Burst Time

P1 0 8

P2 1 4

P3 2 9

P4 3 5

●​ At time 0, P1 arrives and starts executing.


●​ At time 1, P2 arrives. Since its burst time (4) is less than the remaining time of P1
(8), P1 is preempted, and P2 starts executing.
●​ This process continues with each new arrival being checked to see if it should
preempt the current process.

Gantt Chart: A Gantt chart visually represents the execution order of processes over time.
Here's a hypothetical illustration of how SRTF would execute the above example:

Time 0 1 2 3 4 5 6 7 8 9 10 11 12 13

P P1 P2 P2 P1 P1 P4 P4 P4 P1 P1 P3 P3 P3 P3

Given Data:

Process Arrival Time (AT) Burst Time (BT)

P1 0 8

P2 1 4

P3 2 9

P4 3 5

Step-by-Step Calculation:

1.​ Completion Time (CT) is the time when a process finishes execution.
2.​ Turnaround Time (TAT) is calculated as TAT=CT−AT\text{TAT} = \text{CT} -
\text{AT}TAT=CT−AT.
3.​ Waiting Time (WT) is calculated as WT=TAT−BT\text{WT} = \text{TAT} -
\text{BT}WT=TAT−BT.

SRTF Execution Summary:

Based on the arrival times and burst times, here is how the processes are executed in the
SRTF scheduling order (from the previous Gantt chart):
Process Arrival Time Burst Time Completion Time Turnaround Time Waiting Time
(AT) (BT) (CT) (TAT) (WT)

P1 0 8 9 9-0=9 9-8=1

P2 1 4 5 5-1=4 4-4=0

P3 2 9 15 15 - 2 = 13 13 - 9 = 4

P4 3 5 13 13 - 3 = 10 10 - 5 = 5

Filled Table for Processes:

Process Arrival Time Burst Time Completion Time Turnaround Time Waiting Time
(AT) (BT) (CT) (TAT) (WT)

P1 0 8 9 9 1

P2 1 4 5 4 0

P3 2 9 15 13 4

P4 3 5 13 10 5

Final Metrics:

1.​ Average Turnaround Time (TAT) = 9+4+13+104=9\frac{9 + 4 + 13 + 10}{4} =


949+4+13+10​=9
2.​ Average Waiting Time (WT) = 1+0+4+54=2.5\frac{1 + 0 + 4 + 5}{4} =
2.541+0+4+5​=2.5

Performance Metrics:

1.​ Turnaround Time (TAT): The total time taken from the arrival of the process to its
completion.
2.​ Waiting Time (WT): The total time a process spends waiting in the ready queue.
3.​ Average Waiting Time: The sum of waiting times for all processes divided by the
number of processes.

Visual Enhancements:

●​ Icons & Graphics: Use icons representing processes, CPU time, and preemptions.
●​ Colors: Use different colors for processes running, waiting, and preempted states to
enhance clarity.
●​ Charts/Graphs: Include bar charts for performance metrics like average waiting
time and turnaround time for comparison.

Applications:

●​ SRTF is ideal for systems where job lengths are highly variable and where
minimizing waiting time is a critical factor. It is typically used in:
○​ Real-Time Operating Systems (RTOS) where responsiveness is crucial.
○​ Process Scheduling in batch systems for minimizing latency.

Conclusion: SRTF is a dynamic scheduling algorithm that aims to improve system


efficiency by reducing the average waiting time. However, its potential for causing
starvation and the overhead of preemptive scheduling should be carefully considered when
choosing it for a specific system.

3. Advantages and Disadvantages


✅ Advantages:
●​ Minimizes average turnaround time and waiting time.
●​ Efficient for systems requiring fast responses.

❌ Disadvantages:
●​ May cause starvation for longer processes.
●​ High CPU overhead due to frequent preemptions.

4. Conclusion
SRTF is an optimal scheduling algorithm for minimizing turnaround time. However, its
preemptive nature can lead to starvation for longer processes. It is best suited for
environments where short processes arrive frequently and require quick execution.

You might also like