-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSched.cpp
83 lines (79 loc) · 2.21 KB
/
Sched.cpp
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
#include <Sched.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <os_sim.h>
void Sorting(DispProc *proc,int iProcInRQ,int iSortOn)
{
DispProc Temp;
int i,j,k;
for ( i = 1 ; i <= (iProcInRQ - 1) ; i++ )
{
for ( j = 0 ; j < i ; j++ )
{
if ( (iSortOn == SJF) && (proc[j].iBurst > proc[i].iBurst) )
{
memcpy(&Temp,&proc[j],sizeof(DispProc));
memcpy(&proc[j],&proc[i],sizeof(DispProc));
for ( k = i ; k > j ; k-- )
memcpy(&proc[k],&proc[k-1],sizeof(DispProc));
memcpy(&proc[k+1],&Temp,sizeof(DispProc));
}
else if( (iSortOn == PRIORITY) && (proc[j].iPriority > proc[i].iPriority) )
{
memcpy(&Temp,&proc[j],sizeof(DispProc));
memcpy(&proc[j],&proc[i],sizeof(DispProc));
for ( k = i ; k > j ; k-- )
memcpy(&proc[k],&proc[k-1],sizeof(DispProc));
memcpy(&proc[k+1],&Temp,sizeof(DispProc));
}
}
}
for ( i = 0 ; i <= (iProcInRQ-1) ; i++ )
{
printf("Burst size in sorting is %d %d\n",proc[i].iPriority,iProcInRQ);
}
printf("\n");
}
void UpdateDisplayRQAtEveryBeat(DispProc *proc,ProcessDef data)
{
int i;
for(i = 0;i<MAXIMUM_PROC;i++)
{
if(data.iProcessID == proc[i].iProcessID)
{
proc[i].iBurst = data.iBurstTime;
}
}
}
int GenRendTime()
{
int iTime;
do
{
iTime = rand();
iTime = iTime/(1000*1000*100);
}while(iTime == 0);
return iTime;
}
void FillProcessInfo(ProcessDef *ProcessInfo)
{
int i;
for(i = 0;i<MAXIMUM_PROC;i++)
{
if(false == ProcessInfo[i].bFill)
{
ProcessInfo[i].bFill = true;
ProcessInfo[i].iBurstTime = GenRendTime();
ProcessInfo[i].iArrivalTime = GenRendTime();
ProcessInfo[i].iPriority = GenRendTime();
sprintf(ProcessInfo[i].cProcessName,"Process %d",(i+1));
ProcessInfo[i].iProcessID = i+1;
ProcessInfo[i].bInJobQ = true;
break;
}
else
{
}
}
}