-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOS_Q2
More file actions
97 lines (91 loc) · 1.85 KB
/
OS_Q2
File metadata and controls
97 lines (91 loc) · 1.85 KB
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
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int count,i,j,m=0,n,y=0,time,remain=0,min,flag=0;
int wait_time=0,turn_a_time=0,a_time[10],b_time[10],p[10],z[10];
float k=0,x=0;
printf("Enter number of Process:\t ");
scanf("%d",&n);
printf("\n\tArrival time should be greater than 2 as CPU remains idle for first 3 secs.\n");
printf("\n\tBurst time should be less tha 10\n");
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Number %d :",count+1);
scanf("%d",&a_time[count]);
scanf("%d",&b_time[count]);
}
for(i=0;i<n;i++)
{ if(a_time[i]==0)
{ printf("\nS INVALID ARRIVAL TIME\n");
getch();
exit(1);
}
}
for(i=0;i<n;i++)
{ if(a_time[i]<3)
{ printf("\nS INVALID Arrival Time it should be greater than 3\n");
getch();
exit(1);
}
}
printf("\n\n\tPROCESS\t| TAT |Waiting Time\n");
printf("\t-----------------------------------------\n");
for(i=0;i<n;i++)
{
m=m+b_time[i];
}
min=m;
time=m;
for(i=0;i<n;i++)
{ if(a_time[i]<time)
{
time=a_time[i];
}
}
for(i=time;i<=m;i=i+b_time[j])
{ min=m;
remain=0;
flag=0;
for(count=0;count<n;count++)
{
if(a_time[count]<=i)
{
if(b_time[count]<min)
{
min = b_time[count];
j=count;
flag=1;
}
remain=1;
}
}
if(flag==1&&remain==1)
{
wait_time=i-a_time[j];
turn_a_time=wait_time+b_time[j];
printf("\tP[%d]\t|\t%d\t|\t%d\n",j+1,turn_a_time,wait_time);
k=k+wait_time;
x=x+turn_a_time;
a_time[j]=m+1;
p[y]=j+1;
z[y]=i;
y++;
}
}
printf("\n\nAVERAGE WAITING TIME= %.2f\n",k/n);
printf("AVERAGE TURNAROUND TIME = %.2f",x/n);
printf("\n\n\nTOTAL TIME TAKEN BY PROCESSOR TO COMPLETE ALL JOBS: %d",m);
printf("\n\nQUEUE::ORDER OF EXECUTION:\n");
printf("\nPROCESS ");
for(i=0;i<n;i++)
{
printf(" P[%d] ",p[i]);
if(i==(n-1))
{
printf("End");
}
}
return 0;
}