-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.java
More file actions
76 lines (59 loc) · 2.1 KB
/
Process.java
File metadata and controls
76 lines (59 loc) · 2.1 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
public class Process {
private ProcessControlBlock pcb;
private int arrivalTime;
private int burstTime;
private int memoryRequirements;
private double responseTime;
public Process(int arrivalTime, int burstTime, int memoryRequirements) {
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
this.memoryRequirements = memoryRequirements;
this.pcb = new ProcessControlBlock();
}
public ProcessControlBlock getPCB() {
return this.pcb;
}
public void run() {
/* TODO: you need to add some code here
* Hint: this should run every time a process starts running */
if (this.pcb.getStartTimes().isEmpty())
responseTime = CPU.clock - arrivalTime;
this.pcb.setState(ProcessState.RUNNING,CPU.clock);
CPU.clock += 2;
}
public void waitInBackground() {
/* TODO: you need to add some code here
* Hint: this should run every time a process stops running */
this.pcb.setState(ProcessState.READY,CPU.clock);
CPU.clock += 2;
}
public double getWaitingTime() {
/* TODO: you need to add some code here
* and change the return value */
return getTurnAroundTime() - getBurstTime();
}
public double getResponseTime() {
/* TODO: you need to add some code here
* and change the return value */
return this.responseTime;
}
public double getTurnAroundTime() {
/* TODO: you need to add some code here
* and change the return value */
try {
return this.pcb.getStartTimes().get(0) - this.pcb.getStopTimes().get(this.pcb.getStopTimes().size()-1);
} //In case something goes wrong
catch (IndexOutOfBoundsException e ) {
return CPU.clock - this.pcb.getStartTimes().get(0);
}
}
public int getMemoryRequirements() {
return this.memoryRequirements;
}
public int getBurstTime() {
return this.burstTime;
}
public void setBurstTime(int burstTime) {
this.burstTime = burstTime;
}
}