-
Notifications
You must be signed in to change notification settings - Fork 0
/
Process.cpp
107 lines (84 loc) · 2.39 KB
/
Process.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "Process.h"
Process::Process() {
this->PID = 0;
this->submissionTime = 0;
this->priority = 0;
this->remainsExecutionTime = 0;
this->blockTime = 0;
this->timesExecuted = 0;
this->waitingTime = 0;
this->responseTime = 0;
totalExecutationTime = remainsExecutionTime;
}
Process::Process(std::tuple<int, double, int, double, double, std::vector<Page>> _process) {
this->PID = _getPID(_process);
this->submissionTime = _getSubmissionTime(_process);
this->priority = _getPriority(_process);
this->remainsExecutionTime = _getExecutionTime(_process);
this->blockTime = _getBlockedTime(_process);
this->waitingTime = -1;
this->responseTime = -1;
this->timesExecuted = 0;
this->pages = _getPages(_process);
totalExecutationTime = remainsExecutionTime;
}
int Process::getPID() {
return PID;
}
double Process::getSubmissionTime() {
return submissionTime;
}
int Process::getPriority() {
return priority;
}
int Process::getTimesExecuted() {
return timesExecuted;
}
double Process::getExecutionTime() {
return remainsExecutionTime;
}
double Process::getBlockTime() {
return blockTime;
}
double Process::getResponseTime() {
return responseTime;
}
double Process::getWaitingTime() {
return waitingTime;
}
double Process::getTurnaroundTime() {
return turnaroundTime;
}
Page Process::getPage() {
if (pages.empty()) return Page(0,0,0,0);
if (pages[0].getFirstUse() > this->totalExecutationTime - remainsExecutionTime)
return Page(0,0,0,0);
if (pages[0].getLifeTime() > 0)
return pages[0];
else {
pages.erase(pages.begin());
if (pages[0].getLifeTime() > 0)
return pages[0];
}
}
std::vector<Page> Process::getAllPages() {
return pages;
}
void Process::updateSubmissionTime(double _submissionTime) {
this->submissionTime = _submissionTime;
}
void Process::setResponseTime(double _elapsedTime) {
this->responseTime = _elapsedTime - this->submissionTime;
}
void Process::setWaitingTime(double _elapsedTime) {
this->waitingTime = _elapsedTime - (this->submissionTime + this->totalExecutationTime);
}
void Process::setTurnaroundTime(double _elapsedTime) {
this->turnaroundTime = _elapsedTime - submissionTime;
}
void Process::incrementTimesExecuted() {
this->timesExecuted += 1;
}
void Process::setPriority(int priority) {
this->priority = priority;
}