20CSE038
20CSE038
#include<iostream>
float roundRobinAvgWaitingTime;
int rem_bt[n];
rem_bt[i] = bt[i];
int t = 0;
while (1)
if (rem_bt[i] > 0)
done = false;
t += quantum;
rem_bt[i] -= quantum;
}
else
t = t + rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
if (done == true)
break;
int main()
wt[0] = 0;
wt[i] = 0;
wt[i] += bt[j];
}
avwt += wt[i];
avtat += tat[i];
avwt /= i;
cout << "\n\nAverage Waiting Time for FCFS:" << avwt << endl;
int A[100][4];
A[0][1] = 10;
A[1][1] = 29;
A[2][1] = 3;
A[3][1] = 7;
A[4][1] = 12;
A[0][0] = 1;
A[1][0] = 2;
A[2][0] = 3;
A[3][0] = 4;
A[4][0] = 5;
index = i;
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
A[0][2] = 0;
A[i][2] = 0;
total += A[i][2];
avg_wt = (float)total / n;
total = 0;
total += A[i][3];
avg_tat = (float)total / n;
cout << "Average Waiting Time for SJF= " << avg_wt << endl;
else
{
cout << "FCFS gives minimum average waiting time\n";
return 0;
Problem 2:
#include<bits/stdc++.h>
#include <stdlib.h>
struct Resource {
int A;
int B;
int C;
int D;
};
struct Allocation {
int A1;
int B1;
int C1;
int D1;
};
struct Max {
int A2;
int B2;
int C2;
int D2;
};
void compute();
int p, current[4];
int main() {
p = 5;
FILE *fip;
if (fip == NULL) {
perror("Error Occurred\n");
exit(EXIT_FAILURE);
int i = 0;
i++;
}
fclose(fip);
FILE *fip1;
if (fip1 == NULL) {
perror("Error Occurred\n");
exit(EXIT_FAILURE);
i = 0;
i++;
fclose(fip1);
FILE *fip2;
if (fip2 == NULL) {
perror("Error Occurred\n");
exit(EXIT_FAILURE);
i = 0;
i++;
fclose(fip2);
p1[0][0] = 0;
p1[0][1] = 4;
p1[0][2] = 2;
p1[0][3] = 0;
cout << "Initial Available Resources: " << current[0] << " " << current[1] << " " << current[2] << " "
<< current[3] << "\n\n";
cout << " " << Max[i][0] << " " << Max[i][1] << " " << Max[i][2] << " " << Max[i][3] << " ";
cout << " " << allocation[i][0] << " " << allocation[i][1] << " " << allocation[i][2] << " " <<
allocation[i][3] << " ";
cout << " " << need[i][0] << " " << need[i][1] << " " << need[i][2] << " " << need[i][3];
compute();
if (p1[0][0] <= current[0] && p1[0][1] <= current[1] && p1[0][2] <= current[2] && p1[0][3] <=
current[3]) {
cout << "\n\nIf a request from p1 arrives for (0,4,2,0) Then it's granted immediately" << endl;
} else {
cout << "\n\nIf a request from p1 arrives for (0,4,2,0) Then it's not granted immediately" << endl;
return 0;
void compute() {
deadlock = false;
executed[i] = false;
int i, j;
j++;
if (need[j][0] <= current[0] && need[j][1] <= current[1] && need[j][2] <= current[2] && need[j]
[3] <= current[3]) {
if (!executed[j]) {
executed[j] = true;
current[0] += allocation[j][0];
current[1] += allocation[j][1];
current[2] += allocation[j][2];
current[3] += allocation[j][3];
cout << "\nCurrent: " << current[0] << " " << current[1] << " " << current[2] << " " <<
current[3] << "\n";
deadlock = true;
break;
if (!deadlock) {
break;
} else {
deadlock = false;
Problem 3:
#include <bits/stdc++.h>
ll pages[100005],n;
void opr()
ll sz = 2;
vector<ll>frame;
ll faults=0;
ll it;
if(pages[i]==frame[it])
break;
if (it==frame.size())
if (sz>frame.size())
frame.push_back(pages[i]);
}
else
ll pos=i+1;
ll in=INT_MIN,high=pos;
ll j;
for (j=pos;j<n;j++)
if (frame[k]==pages[j])
if (j>high)
high = j;
in = k;
break;
if (j==n)
in=k;
break;
}
}
frame[in]=pages[i];
faults++;
if(faults == 9)cout<<"Total Page Faults: "<< faults <<"\nFrame number is " <<
sz <<endl;
int main()
#ifndef ONLINE_JUDGE
#endif
cin>>n;
cin>>pages[i];
}
opr();
return 0;