-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.cpp
More file actions
79 lines (70 loc) · 2 KB
/
Copy pathprocess.cpp
File metadata and controls
79 lines (70 loc) · 2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* William Ruman 2015 -- Truman State University
* Implementation of the process class defined in process.hpp
*/
#include "process.hpp"
#include <iostream>
#include <iomanip>
#include <cstdio>
Process::Process() {
this->processNumber = 0;
this->arrivalTime = 0;
this->executionTime = 0;
this->cpuTime = 0;
this->waitingTime = 0;
this->departureTime = 0;
this->turnaroundTime = 0;
this->done = false;
}
Process::Process(unsigned int pNum, unsigned int arriveT, unsigned int execT) {
this->processNumber = pNum;
this->arrivalTime = arriveT;
this->executionTime = execT;
this->cpuTime = 0;
this->waitingTime = 0;
this->departureTime = 0;
this->turnaroundTime = 0;
this->done = false;
}
// Diagnostic information for the process
void Process::print() {
std::cout << "Process " << processNumber << " at " << this << std::endl;
}
// Pretty print process statistics with set column widths
void Process::printRow(){
std::cout << std::setw(7) << processNumber << std::setw(11)
<< arrivalTime << std::setw(13) << departureTime
<< std::setw(10) << cpuTime << std::setw(19)
<< turnaroundTime << std::setw(16) << waitingTime << std::endl;
}
// Return how long the process still needs to run
unsigned int Process::getRemainingTime() {
return executionTime - cpuTime;
}
unsigned int Process::getTurnaroundTime() {
return turnaroundTime;
}
unsigned int Process::getWaitTime() {
return waitingTime;
}
bool Process::isDone() {
return done;
}
// Do nothing, incr wait time
void Process::wait() {
waitingTime++;
}
// Do "work" and check if all work has been done.
// When all work has been done, do final calculations
// for process stats and set done to 'true'
void Process::run() {
cpuTime++;
if (cpuTime >= executionTime) {
done = true;
departureTime = arrivalTime + executionTime + waitingTime;
turnaroundTime = departureTime - arrivalTime;
}
}
unsigned int Process::getArrivalTime() {
return arrivalTime;
}