Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views6 pages

Round Robin Scheduling Examples

Vjvhhc ch.fug chg chch chc

Uploaded by

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

Round Robin Scheduling Examples

Vjvhhc ch.fug chg chch chc

Uploaded by

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

Round Robin Scheduling – Solved Numericals

Case 1: Different Arrival Times


Given:

Process Arrival Time Burst Time

P1 0 10

P2 1 4

P3 2 5

Time Quantum: 4 units

Gantt Chart:

P1 (0–4) → P2 (4–8) → P3 (8–12) → P1 (12–16) → P3 (16–17)

Turnaround Time:

Process Completion Time Arrival Time Turnaround Time

P1 16 0 16

P2 8 1 7

P3 17 2 15

Waiting Time:

Process Turnaround Time Burst Time Waiting Time

P1 16 10 6

P2 7 4 3

P3 15 5 10

Average Turnaround Time = 12.67 units

Average Waiting Time = 6.33 units


Case 2: Same Arrival Times
Given:

Process Arrival Time Burst Time

P1 0 10

P2 0 4

P3 0 5

Time Quantum: 4 units

Gantt Chart:

P1 (0–4) → P2 (4–8) → P3 (8–12) → P1 (12–16) → P3 (16–17) → P1 (17–19)

Turnaround Time:

Process Completion Time Arrival Time Turnaround Time

P1 19 0 19

P2 8 0 8

P3 17 0 17

Waiting Time:

Process Turnaround Time Burst Time Waiting Time

P1 19 10 9

P2 8 4 4

P3 17 5 12

Average Turnaround Time = 14.67 units

Average Waiting Time = 8.33 units


Case 3: 4 Processes, Same Arrival Time (0)
Given:

Process Arrival Time Burst Time

P1 0 5

P2 0 7

P3 0 4

P4 0 6

Time Quantum: 3 units

Gantt Chart:

P1 (0–3) → P2 (3–6) → P3 (6–9) → P4 (9–12) → P1 (12–14) → P2 (14–17) → P3 (17–18) →


P4 (18–21) → P2 (21–22)

Turnaround Time:

Process Completion Time Arrival Time Turnaround Time

P1 14 0 14

P2 22 0 22

P3 18 0 18

P4 21 0 21

Waiting Time:

Process Turnaround Time Burst Time Waiting Time

P1 14 5 9

P2 22 7 15

P3 18 4 14

P4 21 6 15

Average Turnaround Time = 18.75 units

Average Waiting Time = 13.25 units


Case 4: 4 Processes, Different Arrival Times
Given:

Process Arrival Time Burst Time

P1 0 6

P2 2 4

P3 4 8

P4 6 5

Time Quantum: 4 units

Gantt Chart:

P1 (0–4) → P2 (4–8) → P3 (8–12) → P4 (12–16) → P1 (16–18) → P3 (18–22) → P4 (22–23)

Turnaround Time:

Process Completion Time Arrival Time Turnaround Time

P1 18 0 18

P2 8 2 6

P3 22 4 18

P4 23 6 17

Waiting Time:

Process Turnaround Time Burst Time Waiting Time

P1 18 6 12

P2 6 4 2

P3 18 8 10

P4 17 5 12

Average Turnaround Time = 14.75 units

Average Waiting Time = 9.0 units


#include <stdio.h>
#include<conio.h>
#define MAX 10 // Maximum number of processes

// Structure to hold process details


struct Process {
int id; // Process ID
int arrivalTime; // Arrival Time
int burstTime; // Burst Time
int remainingTime; // Remaining Time
int waitingTime; // Waiting Time
int turnaroundTime; // Turnaround Time
};

// Function to implement Round Robin scheduling


void roundRobin(struct Process processes[], int n, int timeQuantum) {
int currentTime = 0; // Tracks current time
int completed = 0;
float totalWaitingTime = 0, totalTurnaroundTime = 0;
int i;
while (completed < n) {
for ( i = 0; i < n; i++) {
if (processes[i].arrivalTime <= currentTime &&
processes[i].remainingTime > 0) {
if (processes[i].remainingTime > timeQuantum) {
processes[i].remainingTime -= timeQuantum;
currentTime += timeQuantum;
} else {
currentTime += processes[i].remainingTime;
processes[i].waitingTime = currentTime -
processes[i].arrivalTime - processes[i].burstTime;
processes[i].turnaroundTime = currentTime -
processes[i].arrivalTime;
totalWaitingTime += processes[i].waitingTime;
totalTurnaroundTime += processes[i].turnaroundTime;
processes[i].remainingTime = 0;
completed++;
}
}
}
}

// Display results
printf("\nProcess ID | Arrival Time | Burst Time | Waiting Time |
Turnaround Time\n");
for (i = 0; i < n; i++) {
printf("%9d | %12d | %10d | %12d | %15d\n", processes[i].id,
processes[i].arrivalTime,
processes[i].burstTime, processes[i].waitingTime,
processes[i].turnaroundTime);
}

// Calculate averages
printf("\nAverage Waiting Time = %.2f\n", totalWaitingTime / n);
printf("Average Turnaround Time = %.2f\n", totalTurnaroundTime / n);
}

// Main function
int main() {
struct Process processes[MAX];
int n, timeQuantum;
int i;
// Input number of processes
printf("Enter the number of processes: ");
scanf("%d", &n);

// Input processes' arrival times and burst times


for ( i = 0; i < n; i++) {
processes[i].id = i + 1;
printf("Enter arrival time and burst time for process %d: ", i +
1);
scanf_s("%d %d", &processes[i].arrivalTime,
&processes[i].burstTime);
processes[i].remainingTime = processes[i].burstTime; // Initialize
remaining time
}

// Input time quantum


printf("Enter time quantum: ");
scanf_s("%d", &timeQuantum);

// Run Round Robin Scheduling


roundRobin(processes, n, timeQuantum);
_getch();
return 0;
}

You might also like