-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.cpp
65 lines (55 loc) · 1.58 KB
/
scheduler.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
#include "scheduler.h"
Scheduler::Scheduler(string input) {
inputFile = input;
avgTurn = 0;
avgResp = 0;
avgWait = 0;
cpuUsage = 0;
pidCount = 0;
timeCounter = 0;
}
void Scheduler::parseInputFile() {
ifstream inFile;
int pidVal;
int arrivalVal;
int burstVal;
inFile.open(inputFile.c_str());
if (inFile.fail())
return;
// Read process values from file and store vector
while (inFile >> pidVal >> arrivalVal >> burstVal) {
processInfo tempProcess = {
pidVal,
true,
arrivalVal,
burstVal,
0,
burstVal
};
process.push_back(tempProcess);
pidCount++;
}
inFile.close();
cout << "Total " << pidCount << " tasks are read from "
<< inputFile << ". Press 'enter' to start..." << endl
<< "==========================================" << endl;
cin.ignore();
}
void Scheduler::printRunProcess(int numPro) {
cout << "<system time " << timeCounter << "> process "
<< numPro << " is running" << endl;
}
void Scheduler::printCompleteProcess(int numPro) {
cout << "<system time " << timeCounter << "> process "
<< numPro << " is finished..." << endl;
}
void Scheduler::printProcessResult() {
cout << "==========================================" << endl;
cout.precision(2);
cout << fixed;
cout << "CPU usage : " << cpuUseQuery() << " %"<< endl;
cout << "Average wait time : " << avgWaitQuery() << endl;
cout << "Average response time : " << avgRespQuery() << endl;
cout << "Average turnaround time : " << avgTurnaroundQuery() << endl;
cout << "==========================================" << endl;
}