-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.py
66 lines (58 loc) · 2.72 KB
/
Process.py
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
class Process:
"""Process class representing a process for scheduling."""
def __init__(self, pid=None, arrival_time=None, burst_time=None, priority=None):
"""Initialize the Process.
Args:
pid (int): Process ID.
arrival_time (float): Arrival time of the process.
burst_time (float): Burst time of the process.
priority (int): Priority of the process.
"""
self.pid = pid
self.arrival_time = arrival_time
self.burst_time = burst_time
self.remaining_time = burst_time
self.start_time = None
self.waiting_time = 0
self.turnaround_time = 0
self.priority = priority
def __str__(self):
"""Return string representation of the process."""
return f"Process {self.pid} - Arrival Time: {self.arrival_time}, Burst Time: {self.burst_time}, Remaining Time: {self.remaining_time}, Waiting Time: {self.waiting_time}, Turnaround Time: {self.turnaround_time}"
def __repr__(self):
"""Return string representation of the process."""
return f"Process {self.pid} - Arrival Time: {self.arrival_time}, Burst Time: {self.burst_time}, Remaining Time: {self.remaining_time}, Waiting Time: {self.waiting_time}, Turnaround Time: {self.turnaround_time}"
def __lt__(self, other):
"""Comparison method for sorting processes based on arrival time."""
return self.arrival_time < other.arrival_time
def serialize(self):
"""Serialize the process attributes."""
return {
"pid": self.pid,
"arrival_time": self.arrival_time,
"burst_time": self.burst_time,
"remaining_time": self.remaining_time,
"waiting_time": self.waiting_time,
"turnaround_time": self.turnaround_time
}
def deserialize(self, data):
"""Deserialize the process attributes from given data."""
if "pid" not in data:
raise ValueError("Process ID not found in data")
self.pid = data["pid"]
if "arrival_time" not in data:
raise ValueError("Arrival time not found in data")
self.arrival_time = data["arrival_time"]
if "burst_time" not in data:
raise ValueError("Burst time not found in data")
self.burst_time = data["burst_time"]
if "remaining_time" in data:
self.remaining_time = data["remaining_time"]
if "waiting_time" in data:
self.waiting_time = data["waiting_time"]
if "turnaround_time" in data:
self.turnaround_time = data["turnaround_time"]
return self
def setStartTime(self, time):
"""Set the start time of the process."""
self.start_time = time