-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.cpp
More file actions
60 lines (54 loc) · 1.32 KB
/
FCFS.cpp
File metadata and controls
60 lines (54 loc) · 1.32 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
/*
AUTHORS: Alex Runciman
FILENAME: FCFS.cpp
DESCRIPTION: Implementation of functions declared in FCFS.h
*/
#include "FCFS.h"
// Run the FCFS scheduler
void FCFS::runScheduler() {
parseInputFile();
waitTime.push_back(0);
for (int i = 0; i < pidCount; i++) {
for (int j = 0; j < process[i].burst; j++) {
printRunProcess(i+INC);
timeCounter++;
}
waitTime.push_back(timeCounter);
printCompleteProcess(i+INC);
}
}
// Returns the average response time
double FCFS::avgRespQuery() {
avgResp = avgWaitQuery();
return avgResp;
}
// Returns the average wait time
double FCFS::avgWaitQuery() {
avgWait = 0;
for (int i = 0; i < pidCount; i++) {
avgWait += waitTime[i] - process[i].arrival;
}
avgWait = avgWait/(pidCount);
return avgWait;
}
// Returns the average turnaround time
double FCFS::avgTurnaroundQuery() {
int tempBurst = 0;
int tempTurn = 0;
for (int i = 0; i < pidCount; i++) {
tempBurst += process[i].burst;
tempTurn = tempBurst - process[i].arrival;
avgTurn += tempTurn;
}
avgTurn = avgTurn/(pidCount);
return avgTurn;
}
// Returns the CPU usage in percentage form
double FCFS::cpuUseQuery() {
double totBurst = 0;
for (int i = 0; i < pidCount; i++) {
totBurst += process[i].burst;
}
totBurst = (totBurst/timeCounter) * 100;
return totBurst;
}