-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.py
More file actions
48 lines (48 loc) · 1.34 KB
/
Process.py
File metadata and controls
48 lines (48 loc) · 1.34 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
class Process:
def __init__(self, state, proc_id, arrival_time, cpu_burst_time, num_bursts, io_time):
'''
state will be 'READY' or 'RUNNING' or 'BLOCKED'
'''
self.state = state
self.id = proc_id
self.arrival_time = arrival_time
self.cpu_burst_time = cpu_burst_time
self.num_bursts = num_bursts
self.io_time = io_time
'''
calculated parameters
'''
self.cpu_comp_time = self.cpu_burst_time
self.wait_time = 0
self.turnaround_time = self.cpu_burst_time + self.wait_time
def __cmp__(self, other):
if self.cpu_burst_time > other.cpu_burst_time:
return 1
elif self.cpu_burst_time < other.cpu_burst_time:
return -1
else:
if self.io_time > other.io_time:
return 1
elif self.io_time < other.io_time:
return -1
else:
if self.arrival_time > other.arrival_time:
return 1
elif self.arrival_time < other.arrival_time:
return -1
else:
return cmp(self.proc_id, other.proc_id)
def update_wait_time(self,time):
self.wait_time += time
def update_cpu_completion_time(self,time):
self.cpu_comp_time -= time
def update_num_bursts(self):
self.num_bursts -= 1
def get_cpu_burst_time(self):
return self.cpu_burst_time
def get_cpu_completion_time(self):
return self.cpu_comp_time
def get_wait_time(self):
return self.wait_time
def get_turnaround_time(self):
return self.turnaround_time