-
Notifications
You must be signed in to change notification settings - Fork 0
/
Process.java
118 lines (96 loc) · 2.98 KB
/
Process.java
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
108
109
110
111
112
113
114
115
116
117
118
/*
*
* @Course : Operating Systems , Lab 2
* @Author : Sanchit Mehta<[email protected]>
* @Desc: Maintains all the process data
*
*/
import java.util.*;
import java.io.*;
public class Process implements Comparable < Process > {
//From input
int arrivalTime;
int totalCPUTime;
int burstTime;
int multiplier;
int procID;
//Time Exausted to determine completion
int totalCPUTimeRemaining = 0;
int totalBurstTimeExausted = 0;
//Burst Info
int currCPUBurst = 0;
int currIOBurst = 0;
//Final Outputs
int finishingTime = 0;
int ioTime = 0;
int waitingTime = 0;
//RR
int lastRunning = 0;
public Process(int A, int B, int C, int M,int id) {
this.arrivalTime = A;
this.burstTime = B;
this.totalCPUTime = C;
this.multiplier = M;
this.procID = id;
this.totalCPUTimeRemaining = C;
}
public void clear(){
totalCPUTimeRemaining = totalCPUTime;
totalBurstTimeExausted = 0;
currCPUBurst = 0;
currIOBurst = 0;
finishingTime = 0;
ioTime = 0;
waitingTime = 0;
}
@Override
public String toString() {
return arrivalTime + " " + burstTime + " " + totalCPUTime + " " + multiplier;
}
public void setRandomBurstForCPU() {
int random = randomGenerator.get(this.burstTime);
currCPUBurst = random;
currIOBurst = multiplier*random;
}
public void setRandomBurstForIO() {
currIOBurst = randomGenerator.get(this.burstTime);
}
//Sorts processes by arrival time by defaulted
public int compareTo(Process p2) {
if (this.arrivalTime == p2.arrivalTime)
return 0;
return this.arrivalTime > p2.arrivalTime ? 1 : -1;
}
public void addRunTimes() {
currCPUBurst--;
totalCPUTimeRemaining--;
}
//Static class to get a random number from the pre generated randno file
static class randomGenerator {
private static ArrayList < Integer > randomNums = new ArrayList < Integer > ();
private static int count = 0;
static File file = new File("random-numbers.txt");
static void initialise() {
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
while ((line = reader.readLine()) != null) {
randomNums.add(Integer.parseInt(line.trim()));
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
static int get(int U) {
if (randomNums.size() == 0)
randomGenerator.initialise();
return 1 + (randomNums.get(count++) % U);
}
static void resetPtr() {
count = 0;
}
}
}