-
Notifications
You must be signed in to change notification settings - Fork 14
/
MFQS.c
123 lines (105 loc) · 2.73 KB
/
MFQS.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<stdio.h>
struct process
{
char name;
int AT,BT,WT,TAT,RT,CT;
}Q1[10],Q2[10],Q3[10];/*Three queues*/
int n;
void sortByArrival()
{
struct process temp;
int i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(Q1[i].AT>Q1[j].AT)
{
temp=Q1[i];
Q1[i]=Q1[j];
Q1[j]=temp;
}
}
}
}
int main()
{
int i,j,k=0,r=0,time=0,tq1=5,tq2=8,flag=0;
char c;
printf("Enter no of processes:");
scanf("%d",&n);
for(i=0,c='A';i<n;i++,c++)
{
Q1[i].name=c;
printf("\nEnter the arrival time and burst time of process %c: ",Q1[i].name);
scanf("%d%d",&Q1[i].AT,&Q1[i].BT);
Q1[i].RT=Q1[i].BT;/*save burst time in remaining time for each process*/
}
sortByArrival();
time=Q1[0].AT;
printf("Process in first queue following RR with qt=5");
printf("\nProcess\t\tRT\t\tWT\t\tTAT\t\t");
for(i=0;i<n;i++)
{
if(Q1[i].RT<=tq1)
{
time+=Q1[i].RT;/*from arrival time of first process to completion of this process*/
Q1[i].RT=0;
Q1[i].WT=time-Q1[i].AT-Q1[i].BT;/*amount of time process has been waiting in the first queue*/
Q1[i].TAT=time-Q1[i].AT;/*amount of time to execute the process*/
printf("\n%c\t\t%d\t\t%d\t\t%d",Q1[i].name,Q1[i].BT,Q1[i].WT,Q1[i].TAT);
}
else/*process moves to queue 2 with qt=8*/
{
Q2[k].WT=time;
time+=tq1;
Q1[i].RT-=tq1;
Q2[k].BT=Q1[i].RT;
Q2[k].RT=Q2[k].BT;
Q2[k].name=Q1[i].name;
k=k+1;
flag=1;
}
}
if(flag==1)
{printf("\nProcess in second queue following RR with qt=8");
printf("\nProcess\t\tRT\t\tWT\t\tTAT\t\t");
}for(i=0;i<k;i++)
{
if(Q2[i].RT<=tq2)
{
time+=Q2[i].RT;/*from arrival time of first process +BT of this process*/
Q2[i].RT=0;
Q2[i].WT=time-tq1-Q2[i].BT;/*amount of time process has been waiting in the ready queue*/
Q2[i].TAT=time-Q2[i].AT;/*amount of time to execute the process*/
printf("\n%c\t\t%d\t\t%d\t\t%d",Q2[i].name,Q2[i].BT,Q2[i].WT,Q2[i].TAT);
}
else/*process moves to queue 3 with FCFS*/
{
Q3[r].AT=time;
time+=tq2;
Q2[i].RT-=tq2;
Q3[r].BT=Q2[i].RT;
Q3[r].RT=Q3[r].BT;
Q3[r].name=Q2[i].name;
r=r+1;
flag=2;
}
}
{if(flag==2)
printf("\nProcess in third queue following FCFS ");
}
for(i=0;i<r;i++)
{
if(i==0)
Q3[i].CT=Q3[i].BT+time-tq1-tq2;
else
Q3[i].CT=Q3[i-1].CT+Q3[i].BT;
}
for(i=0;i<r;i++)
{
Q3[i].TAT=Q3[i].CT;
Q3[i].WT=Q3[i].TAT-Q3[i].BT;
printf("\n%c\t\t%d\t\t%d\t\t%d\t\t",Q3[i].name,Q3[i].BT,Q3[i].WT,Q3[i].TAT);
}
}