-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessControlBlock.java
More file actions
57 lines (45 loc) · 1.68 KB
/
ProcessControlBlock.java
File metadata and controls
57 lines (45 loc) · 1.68 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
import java.util.ArrayList;
public class ProcessControlBlock {
private final int pid;
private ProcessState state;
// the following two ArrayLists should record when the process starts/stops
// for statistical purposes
private ArrayList<Integer> startTimes; // when the process starts running
private ArrayList<Integer> stopTimes; // when the process stops running
private static int pidTotal= 0;
public ProcessControlBlock() {
this.state = ProcessState.NEW;
this.startTimes = new ArrayList<Integer>();
this.stopTimes = new ArrayList<Integer>();
/* TODO: you need to add some code here
* Hint: every process should get a unique PID */
this.pid = pidTotal; // change this line
pidTotal++;
}
public ProcessState getState() {
return this.state;
}
public void setState(ProcessState state, int currentClockTime) {
/* TODO: you need to add some code here
* Hint: update this.state, but also include currentClockTime
* in startTimes/stopTimes */
if (state == ProcessState.RUNNING){
this.startTimes.add(currentClockTime);
} else if (state == ProcessState.READY) {
this.stopTimes.add(currentClockTime);
if (this.state == ProcessState.NEW) { CPU.clock++; }
} else {
this.stopTimes.add(currentClockTime);
}
this.state = state;
}
public int getPid() {
return this.pid;
}
public ArrayList<Integer> getStartTimes() {
return startTimes;
}
public ArrayList<Integer> getStopTimes() {
return stopTimes;
}
}