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

roundrobin_less_queue

This document is a C program that implements the Round Robin scheduling algorithm for process management. It calculates and displays the completion time, turnaround time, waiting time, and response time for a set of processes based on their arrival and burst times. The program also computes and outputs the average turnaround time, waiting time, and response time after processing all the tasks.

Uploaded by

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

roundrobin_less_queue

This document is a C program that implements the Round Robin scheduling algorithm for process management. It calculates and displays the completion time, turnaround time, waiting time, and response time for a set of processes based on their arrival and burst times. The program also computes and outputs the average turnaround time, waiting time, and response time after processing all the tasks.

Uploaded by

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

#include <stdio.

h>

int at[10], bt[10], ct[10], wt[10], tat[10], rt[10];


int queue[100], front = 0, rear = -1;

void insert(int p) {
queue[++rear] = p;
}

int delete() {
return queue[front++];
}

int main() {
int n, tq, time = 0;
float totalWT = 0, totalTAT = 0, totalRT = 0;

printf("Enter number of processes: ");


scanf("%d", &n);

int tempBT[10], visited[10] = {0};

// Input Arrival Time and Burst Time


for (int i = 0; i < n; i++) {
printf("Process %d, AT, BT: ", i + 1);
scanf("%d %d", &at[i], &bt[i]);
tempBT[i] = bt[i];
rt[i] = -1; // Initialize response time
}

printf("Enter Time Quantum: ");


scanf("%d", &tq);

insert(0); // Start with process 0


visited[0] = 1;

// Round Robin Scheduling


while (front <= rear) {
int p = delete();

if (rt[p] == -1) { // First time process is visited


rt[p] = time - at[p];
totalRT += rt[p];
}

int execTime = (bt[p] > tq) ? tq : bt[p]; // Execute the process for a
time quantum
time += execTime;
bt[p] -= execTime;

// Add new processes to the queue


for (int i = 0; i < n; i++) {
if (!visited[i] && at[i] <= time) {
insert(i);
visited[i] = 1;
}
}

if (bt[p] > 0) { // Process not finished, reinsert to queue


insert(p);
} else { // Process finished
ct[p] = time;
tat[p] = ct[p] - at[p];
wt[p] = tat[p] - tempBT[p];
totalTAT += tat[p];
totalWT += wt[p];
}
}

// Output results
printf("\nPID\tAT\tBT\tCT\tTAT\tWT\tRT\n");
for (int i = 0; i < n; i++) {
printf("P%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i + 1, at[i], tempBT[i], ct[i],
tat[i], wt[i], rt[i]);
}

printf("\nAverage TAT = %.2f\nAverage WT = %.2f\nAverage RT = %.2f\n", totalTAT


/ n, totalWT / n, totalRT / n);

return 0;
}

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