-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_13.c
79 lines (61 loc) · 1.53 KB
/
lab_13.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
#include<stdio.h>
//Deadline = i^th quantum of time by which the process to finish -->> we prioritize on this.!
//release time = start time
//exection = time required with the processor.
//PROC: 0 INDICATES NO PROCESS
void main()
{
int N_proc,i,wait_prev,k,temp,m,l;
printf("\nEnter the no of processes:");
scanf("%d",&N_proc);
int exec[N_proc],start[N_proc],deadline[N_proc], flag[N_proc];
for(i=0;i<N_proc;i++)
flag[N_proc] = 0;
wait_prev = 0;
for(i=0;i<N_proc;i++)
{
printf("\nEnter absolute start time, exec time and absolute deadline for process %d:",i+1);
scanf("%d %d %d", &start[i], &exec[i], &deadline[i]);
}
int time_quatum = 0;
int end_false = 1;
int smallest_slack = 10000;
int index = -1;
int count = 0;
while(end_false)
{
for(i = 0; i< N_proc;i++)
{
if(start[i] == time_quatum || exec[index] == 0)
{
if(flag[i] != 1)
{
if(((deadline[i] - time_quatum) - exec[i]) < smallest_slack)
{
smallest_slack = (deadline[i] - time_quatum);
//printf("\n min deadline %d, proc %d , time %d, difference %d", smallest_slack, i+1, time_quatum,(deadline[i] - time_quatum) );
index = i;
}
}
}
}
if(exec[index] == 0)
{
smallest_slack = 10000;
index=-1;
}
if(index!=-1)
{
printf("\n From time quantum %d to %d, proc %d", time_quatum,time_quatum+1, index+1);
exec[index]--;
if(exec[index] == 0)
{
flag[index]=1;
count++;
}
}
if(count == N_proc)
end_false = 0;
time_quatum++;
}
}