-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (62 loc) · 1.34 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
#@author Josue Ruiz CS 431
import os.path
import time
import queue
from itertools import cycle
from pnode import pnode
CPU_TIME = 500
SJF_list = {}
q = queue.Queue()
execution_time = []
result = []
def load_list(num, filename):
temp_p = pnode(num)
counter = 0
for line in open(filename):
li=line.strip()
if not li.startswith("#"):
counter = counter + int(li.split()[1])
temp_p.add(int(li))
q.put(temp_p)
execution_time.append(counter)
def prep():
state = True
num = 0
while(state):
filename = "p"+ str(num)+".txt"
if os.path.exists(filename) and int(num) < 100:
print("File: "+str(num))
load_list(int(num), filename)
elif(int(num) >= 100 and os.path.exists(filename)):
print("Max files read reached computing the rest")
state = False
else:
state = False
num = num + 1
for x in range(q.qsize()):
result.append(CPU_TIME)
# def move_forward(pid):
# result[pid] = CPU_TIME
# temp = q.get()
# q.put(temp)
# return None
# def calculate(pid):
# temp = result[pid] - q.queue[0].current()
# if temp <= 0:
# temp = abs(temp)
# q.queue[0].set(temp)
# move_forward(pid)
# elif temp > 0:
# result[pid] = temp
# q.queue[0].next()
# else:
# print("error!")
# return None
def main():
#prepares the data structures an necessary information
prep()
FCFS()
SJF()
RR()
if __name__== "__main__":
main()