0% found this document useful (0 votes)
13 views2 pages

Round Robin

round rovin

Uploaded by

yash yadav
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)
13 views2 pages

Round Robin

round rovin

Uploaded by

yash yadav
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/ 2

#include <stdio.

h>
int main() {
int n;
printf("Enter Total Number of Processes: ");
scanf("%d", &n);
int arr_time[n], burst_time[n], remaining_time[n];
int wait_time = 0, ta_time = 0;
int total_time = 0, completed_processes = n;
// Input process details (arrival time, burst time)
for (int i = 0; i < n; i++) {
printf("Enter Arrival Time and Burst Time for Process %d: ", i + 1);
scanf("%d %d", &arr_time[i], &burst_time[i]);
remaining_time[i] = burst_time[i]; // Copy burst times to remaining times
}
// Input the time slice (time quantum)
int time_slot;
printf("Enter Time Slot: ");
scanf("%d", &time_slot);
printf("Process ID Burst Time Turnaround Time Waiting Time\n");
int i = 0; // Process index
while (completed_processes > 0) {
// Check if the process has arrived and has remaining burst time
if (remaining_time[i] > 0 && arr_time[i] <= total_time) {
if (remaining_time[i] <= time_slot) {
// If process can finish in this time slot
total_time += remaining_time[i]; // Update total time by remaining burst time
remaining_time[i] = 0; // Process finishes
completed_processes--; // One less process to execute
// Calculate turnaround and waiting times
int turnaround_time = total_time - arr_time[i];
int waiting_time = turnaround_time - burst_time[i];
// Accumulate waiting and turnaround times
wait_time += waiting_time;
ta_time += turnaround_time;
// Display process information
printf(" %d %d %d %d\n",
i + 1, burst_time[i], turnaround_time, waiting_time);
} else {
// If process needs more time than the time slot
remaining_time[i] -= time_slot; // Reduce remaining burst time
total_time += time_slot; // Increase total time by time slot
}
}
// Move to the next process in a round-robin fashion
i = (i + 1) % n;
}
// Calculate and display average waiting and turnaround times
float average_wait_time = (float) wait_time / n;
float average_turnaround_time = (float) ta_time / n;
printf("\nAverage Waiting Time: %.2f", average_wait_time);
printf("\nAverage Turnaround Time: %.2f\n", average_turnaround_time);
return 0;
}
Process. Arrival Time. Burst Time
P1 0 8
P2 1 5
P3 2 10
P4 3 11
TQ =6
Assume there are 4 processes (n = 4) and i represents the current process index:

● If i = 0 (first process), i = (0 + 1) % 4 = 1 (next process).


● If i = 1, i = (1 + 1) % 4 = 2.
● If i = 2, i = (2 + 1) % 4 = 3.
● If i = 3 (last process), i = (3 + 1) % 4 = 0 (goes back to the first process).

`
Turn Around Time: Completion Time (CT) - Arrival Time (AT)
For process P1: 25 - 0 = 25
For process P2: 11 -1 = 10
For process P3: 29 - 2 = 27
For process P4: 34 - 3 = 31
Average Turn Around Time is: (25+10+27+31)/4 = 23.25

Process Waiting Time:

P1 = 25-8 =17
P2 = 10-5 =5
P3 = 27-10= 17
P4 = 31-11=20
Average Waiting Time is: (17+5+17+20)/4 = 59/4 = 14.75

You might also like