Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you explain this code to me in C language please? #include #define MaxProcesses 100 #define Q0_RR 8 #define Q1_RR 16 struct Process { int

Can you explain this code to me in C language please?

#include

#define MaxProcesses 100 #define Q0_RR 8 #define Q1_RR 16

struct Process { int burstTime; int waitTime; int arrivalTime; int responseTime; int turnaroundTime; };

int main() { int limit; int counter = 0; struct Process P[MaxProcesses]; int temp[MaxProcesses]; int totalWaitTime = 0; int totalResponseTime = 0; int totalBurstTime = 0; int totalTurnaroundTime = 0; int i, j; printf("Enter Total Number of Processes:"); scanf("%d", &limit); int x = limit; for(i = 0; i < limit; i++) { printf(" Enter Details of Process%d", i + 1); printf(" Enter the arrival time for process:"); scanf("%d", &P[i].arrivalTime); printf("Enter the burst time for process:"); scanf("%d", &P[i].burstTime); temp[i] = P[i].burstTime; } for (i = 0; i < limit; i++) { for (j = 0; j < i; j++) { P[i].waitTime += P[j].burstTime; } P[i].responseTime = P[i].waitTime; } printf(" Process ID Burst Time Turnaround Time Waiting Time "); for(int total = 0, i = 0; x != 0;) { if(temp[i] <= Q1_RR && temp[i] > 0) { total = total + temp[i]; temp[i] = 0; counter = 1; } else if(temp[i] > 0) { temp[i] = temp[i] - Q0_RR; total = total + Q0_RR; } else if(temp[i] > 0) { temp[i] = temp[i] - Q1_RR; total = total + Q1_RR; } if(temp[i] == 0 && counter == 1) { P[i].waitTime = 0; x--; printf("Process[%d] %d %d %d ", i + 1, P[i].burstTime, total - P[i].arrivalTime, total - P[i].arrivalTime - P[i].burstTime); P[i].waitTime = P[i].waitTime + total - P[i].arrivalTime - P[i].burstTime; P[i].turnaroundTime = P[i].turnaroundTime + total - P[i].arrivalTime; counter = 0; } if(i == limit - 1) { i = 0; } else if(P[i + 1].arrivalTime <= total) { i++; } else { i = 0; } } for (i = 0; i < limit; i++) { totalWaitTime += P[i].waitTime; totalResponseTime += P[i].responseTime; totalBurstTime += P[i].burstTime; } printf(" Response time:"); for (i = 0; i < limit; i++) { printf("%d ", P[i].responseTime); }

printf(" Throughput:%f", (float)totalBurstTime / (float)limit ); printf(" Average waiting time:%f", (float)totalWaitTime / (float)limit); return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

Explain the various techniques of Management Development.

Answered: 1 week ago