Powered By Blogger

Aug 12, 2024

Examples of Round Robin CPU Scheduling algorithm

 Evaluate Round Robin  CPU Scheduling algorithm for given Problem Time slice =3 ms.

Process

P1

P2

P3

P4

Process Time

10

5

18

6

Arrival Time

5

3

0

4



Given:

  • Time Slice (Quantum): 3 ms
  • Processes:
    • P1: Burst Time = 10 ms, Arrival Time = 5 ms
    • P2: Burst Time = 5 ms, Arrival Time = 3 ms
    • P3: Burst Time = 18 ms, Arrival Time = 0 ms
    • P4: Burst Time = 6 ms, Arrival Time = 4 ms

Step 1: Order of Execution

We will simulate the round-robin scheduling process:

  1. Process Arrival:

    • P3 arrives at time 0 ms. Burst Time = 18 ms
    • P2 arrives at time 3 ms. Burst Time = 5 ms
    • P4 arrives at time 4 ms. Burst Time = 6 ms
    • P1 arrives at time 5 ms. Burst Time = 10 ms
  2. Time Chart: We will execute each process for up to 3 ms (time slice) in a round-robin manner, continuing until all processes are completed.

    Time (ms)Process ExecutedRemaining Time of Process
    0 - 3P3P3 (15 ms left)
    3 - 6P2P2 (2 ms left)
    6 - 9P4P4 (3 ms left)
    9 - 12P1P1 (7 ms left)
    12 - 15P3P3 (12 ms left)
    15 - 17P2P2 (0 ms, completed)
    17 - 20P4P4 (0 ms, completed)
    20 - 23P1P1 (4 ms left)
    23 - 26P3P3 (9 ms left)
    26 - 29P1P1 (1 ms left)
    29 - 32P3P3 (6 ms left)
    32 - 33P1P1 (0 ms, completed)
    33 - 36P3P3 (3 ms left)
    36 - 39P3P3 (0 ms, completed)

Step 2: Calculate Completion Time, Turnaround Time, and Waiting Time

Completion Time (CT): The time at which each process completes execution.

Turnaround Time (TAT): The total time taken from arrival to completion of a process.
TAT=Completion TimeArrival Time\text{TAT} = \text{Completion Time} - \text{Arrival Time}

Waiting Time (WT): The total time the process spends waiting in the ready queue.
WT=Turnaround TimeBurst Time\text{WT} = \text{Turnaround Time} - \text{Burst Time}

ProcessArrival Time (AT)Burst Time (BT)Completion Time (CT)Turnaround Time (TAT)Waiting Time (WT)
P15 ms10 ms33 ms28 ms18 ms
P23 ms5 ms17 ms14 ms9 ms
P30 ms18 ms39 ms39 ms21 ms
P44 ms6 ms20 ms16 ms10 ms

Step 3: Summary of Metrics

Step 3: Summary of Metrics

  • Average Turnaround Time (TAT): Average TAT=28+14+39+164=24.25 ms\text{Average TAT} = \frac{28 + 14 + 39 + 16}{4} = 24.25 \text{ ms}
  • Average Waiting Time (WT): Average WT=18+9+21+104=14.5 ms\text{Average WT} = \frac{18 + 9 + 21 + 10}{4} = 14.5 \text{ ms}
  • Completion Order: P2, P4, P1, P3
  • Average Turnaround Time: 24.25 ms
  • Average Waiting Time: 14.5 ms
==========================================================================

Consider 3 processes P1, P2 and P3, which require 5, 7 and 4 time units and arrive at time 0, 1 and 3. Draw the Gant chart, process completion sequence and average waiting time for. Round robin scheduling with CPU quantum of 2 time units.


Given:

  • Processes:
    • P1: Burst Time = 5 ms, Arrival Time = 0 ms
    • P2: Burst Time = 7 ms, Arrival Time = 1 ms
    • P3: Burst Time = 4 ms, Arrival Time = 3 ms
  • Time Quantum: 2 ms

Step 1: Gantt Chart

  1. Initial State:

    • P1 arrives at 0 ms.
    • P2 arrives at 1 ms.
    • P3 arrives at 3 ms.
  2. Execution Sequence:

    • Time 0 - 2: P1 executes (Remaining Burst Time: P1 = 3 ms).
    • Time 2 - 4: P2 executes (Remaining Burst Time: P2 = 5 ms).
    • Time 4 - 6: P3 executes (Remaining Burst Time: P3 = 2 ms).
    • Time 6 - 8: P1 executes (Remaining Burst Time: P1 = 1 ms).
    • Time 8 - 10: P2 executes (Remaining Burst Time: P2 = 3 ms).
    • Time 10 - 12: P3 executes (Remaining Burst Time: P3 = 0 ms, completed).
    • Time 12 - 14: P1 executes (Remaining Burst Time: P1 = 0 ms, completed).
    • Time 14 - 16: P2 executes (Remaining Burst Time: P2 = 1 ms).
    • Time 16 - 17: P2 completes (Remaining Burst Time: P2 = 0 ms).

Gantt Chart:



Step 2: Completion Time (CT), Turnaround Time (TAT), and Waiting Time (WT)

Completion Time (CT): The time at which each process completes its execution.

Turnaround Time (TAT): The total time taken from arrival to completion. TAT=Completion Time (CT)Arrival Time (AT)\text{TAT} = \text{Completion Time (CT)} - \text{Arrival Time (AT)}

Waiting Time (WT): The total time a process spends waiting in the ready queue. WT=Turnaround Time (TAT)Burst Time (BT)\text{WT} = \text{Turnaround Time (TAT)} - \text{Burst Time (BT)}

ProcessArrival Time (AT)Burst Time (BT)Completion Time (CT)Turnaround Time (TAT)Waiting Time (WT)
P10 ms5 ms14 ms14 ms9 ms
P21 ms7 ms17 ms16 ms9 ms
P33 ms4 ms12 ms9 ms5 ms

Step 3: Average Waiting Time

  • Average Waiting Time (WT): Average WT=9+9+53=7.67 ms\text{Average WT} = \frac{9 + 9 + 5}{3} = 7.67 \text{ ms}
  • Completion Time (CT): P1 = 14 ms, P2 = 17 ms, P3 = 12 ms

  • Average Turnaround Time (TAT): 13 ms

  • Average Waiting Time (WT): 7.67 ms


No comments:

Post a Comment

Featured Post

Data Analysis

    What is data analysis and its significance?   Data analysis is the process of collecting, transforming, and organizing data to dr...

Popular Posts