oslabcode 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- oslabcode/__init__.py +1 -0
- oslabcode/cli.py +105 -0
- oslabcode/templates/BF.py +16 -0
- oslabcode/templates/Banker.py +65 -0
- oslabcode/templates/CLOOK.py +24 -0
- oslabcode/templates/CSCAN.py +27 -0
- oslabcode/templates/FCFS_DS.py +10 -0
- oslabcode/templates/FCFS_PS.py +28 -0
- oslabcode/templates/FF.py +15 -0
- oslabcode/templates/FIFO.py +25 -0
- oslabcode/templates/LFU.py +36 -0
- oslabcode/templates/LOOK.py +20 -0
- oslabcode/templates/LRU.py +27 -0
- oslabcode/templates/NF.py +22 -0
- oslabcode/templates/Optimal.py +42 -0
- oslabcode/templates/Priority.py +49 -0
- oslabcode/templates/RR.py +52 -0
- oslabcode/templates/SC.py +32 -0
- oslabcode/templates/SCAN.py +24 -0
- oslabcode/templates/SJF.py +47 -0
- oslabcode/templates/SRTF.py +49 -0
- oslabcode/templates/SSTF.py +14 -0
- oslabcode/templates/WF.py +16 -0
- oslabcode-1.0.0.dist-info/METADATA +5 -0
- oslabcode-1.0.0.dist-info/RECORD +28 -0
- oslabcode-1.0.0.dist-info/WHEEL +5 -0
- oslabcode-1.0.0.dist-info/entry_points.txt +2 -0
- oslabcode-1.0.0.dist-info/top_level.txt +1 -0
oslabcode/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.1.0"
|
oslabcode/cli.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
import shutil
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
CODES = {
|
|
7
|
+
"banker": "Banker.py",
|
|
8
|
+
"bf": "BF.py",
|
|
9
|
+
"clook": "CLOOK.py",
|
|
10
|
+
"cscan": "CSCAN.py",
|
|
11
|
+
"fcfs_ds": "FCFS_DS.py",
|
|
12
|
+
"fcfs_ps": "FCFS_PS.py",
|
|
13
|
+
"ff": "FF.py",
|
|
14
|
+
"fifo": "FIFO.py",
|
|
15
|
+
"lfu": "LFU.py",
|
|
16
|
+
"look": "LOOK.py",
|
|
17
|
+
"lru": "LRU.py",
|
|
18
|
+
"nf": "NF.py",
|
|
19
|
+
"optimal": "Optimal.py",
|
|
20
|
+
"priority": "Priority.py",
|
|
21
|
+
"rr": "RR.py",
|
|
22
|
+
"sc": "SC.py",
|
|
23
|
+
"scan": "SCAN.py",
|
|
24
|
+
"sjf": "SJF.py",
|
|
25
|
+
"srtf": "SRTF.py",
|
|
26
|
+
"sstf": "SSTF.py",
|
|
27
|
+
"wf": "WF.py",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def copy_template(code):
|
|
32
|
+
try:
|
|
33
|
+
src = files("oslabcode.templates").joinpath(CODES[code])
|
|
34
|
+
dst = Path.cwd() / CODES[code]
|
|
35
|
+
|
|
36
|
+
shutil.copy(str(src), dst)
|
|
37
|
+
|
|
38
|
+
print(f"Downloaded {CODES[code]}")
|
|
39
|
+
print(f"Saved to {dst}")
|
|
40
|
+
|
|
41
|
+
except Exception as e:
|
|
42
|
+
print(f"Error: {e}")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def list_codes():
|
|
46
|
+
print("\nAvailable Codes:\n")
|
|
47
|
+
|
|
48
|
+
for code in CODES:
|
|
49
|
+
print(code)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def copy_all():
|
|
53
|
+
for code in CODES:
|
|
54
|
+
copy_template(code)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def interactive_menu():
|
|
58
|
+
codes = list(CODES.keys())
|
|
59
|
+
|
|
60
|
+
print("\nAvailable Codes:\n")
|
|
61
|
+
|
|
62
|
+
for i, code in enumerate(codes, start=1):
|
|
63
|
+
print(f"{i}. {code}")
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
choice = int(input("\nChoose option: "))
|
|
67
|
+
|
|
68
|
+
if not (1 <= choice <= len(codes)):
|
|
69
|
+
print("Invalid choice")
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
copy_template(codes[choice - 1])
|
|
73
|
+
|
|
74
|
+
except ValueError:
|
|
75
|
+
print("Please enter a number.")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def main():
|
|
79
|
+
if len(sys.argv) == 1:
|
|
80
|
+
interactive_menu()
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
command = sys.argv[1].lower()
|
|
84
|
+
|
|
85
|
+
if command == "list":
|
|
86
|
+
list_codes()
|
|
87
|
+
|
|
88
|
+
elif command == "all":
|
|
89
|
+
copy_all()
|
|
90
|
+
|
|
91
|
+
elif command in CODES:
|
|
92
|
+
copy_template(command)
|
|
93
|
+
|
|
94
|
+
else:
|
|
95
|
+
print("Code not found.\n")
|
|
96
|
+
|
|
97
|
+
print("Usage:")
|
|
98
|
+
print(" oslabcode")
|
|
99
|
+
print(" oslabcode list")
|
|
100
|
+
print(" oslabcode all")
|
|
101
|
+
print(" oslabcode <code>")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__ == "__main__":
|
|
105
|
+
main()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
blocks = list(map(int, input("Enter block sizes: ").split()))
|
|
2
|
+
processes = list(map(int, input("Enter process sizes: ").split()))
|
|
3
|
+
|
|
4
|
+
for i in range(len(processes)):
|
|
5
|
+
best = -1
|
|
6
|
+
|
|
7
|
+
for j in range(len(blocks)):
|
|
8
|
+
if blocks[j] >= processes[i]:
|
|
9
|
+
if best == -1 or blocks[j] < blocks[best]:
|
|
10
|
+
best = j
|
|
11
|
+
|
|
12
|
+
if best != -1:
|
|
13
|
+
print("Process", i + 1, "allocated to Block", best + 1)
|
|
14
|
+
blocks[best] -= processes[i]
|
|
15
|
+
else:
|
|
16
|
+
print("Process", i + 1, "not allocated")
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
n = int(input("Enter number of processes: "))
|
|
2
|
+
m = int(input("Enter number of resource types: "))
|
|
3
|
+
|
|
4
|
+
alloc = []
|
|
5
|
+
print("\nEnter Allocation Matrix:")
|
|
6
|
+
for i in range(n):
|
|
7
|
+
alloc.append(list(map(int, input().split())))
|
|
8
|
+
|
|
9
|
+
maxm = []
|
|
10
|
+
print("\nEnter Max Matrix:")
|
|
11
|
+
for i in range(n):
|
|
12
|
+
maxm.append(list(map(int, input().split())))
|
|
13
|
+
|
|
14
|
+
avail = list(map(int, input("\nEnter Available Resources: ").split()))
|
|
15
|
+
|
|
16
|
+
need = []
|
|
17
|
+
|
|
18
|
+
for i in range(n):
|
|
19
|
+
row = []
|
|
20
|
+
for j in range(m):
|
|
21
|
+
row.append(maxm[i][j] - alloc[i][j])
|
|
22
|
+
need.append(row)
|
|
23
|
+
|
|
24
|
+
print("\nNeed Matrix:")
|
|
25
|
+
for row in need:
|
|
26
|
+
print(row)
|
|
27
|
+
|
|
28
|
+
finish = [False] * n
|
|
29
|
+
safe = []
|
|
30
|
+
|
|
31
|
+
count = 0
|
|
32
|
+
|
|
33
|
+
while count < n:
|
|
34
|
+
|
|
35
|
+
found = False
|
|
36
|
+
|
|
37
|
+
for i in range(n):
|
|
38
|
+
|
|
39
|
+
if not finish[i]:
|
|
40
|
+
|
|
41
|
+
possible = True
|
|
42
|
+
|
|
43
|
+
for j in range(m):
|
|
44
|
+
if need[i][j] > avail[j]:
|
|
45
|
+
possible = False
|
|
46
|
+
break
|
|
47
|
+
|
|
48
|
+
if possible:
|
|
49
|
+
|
|
50
|
+
for j in range(m):
|
|
51
|
+
avail[j] += alloc[i][j]
|
|
52
|
+
|
|
53
|
+
safe.append("P" + str(i))
|
|
54
|
+
finish[i] = True
|
|
55
|
+
found = True
|
|
56
|
+
count += 1
|
|
57
|
+
|
|
58
|
+
if not found:
|
|
59
|
+
break
|
|
60
|
+
|
|
61
|
+
if count == n:
|
|
62
|
+
print("\nSafe Sequence:")
|
|
63
|
+
print(" -> ".join(safe))
|
|
64
|
+
else:
|
|
65
|
+
print("\nSystem is NOT in a Safe State")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
req = list(map(int, input("Enter requests: ").split()))
|
|
2
|
+
head = int(input("Enter initial head position: "))
|
|
3
|
+
|
|
4
|
+
left = [x for x in req if x < head]
|
|
5
|
+
right = [x for x in req if x >= head]
|
|
6
|
+
|
|
7
|
+
left.sort()
|
|
8
|
+
right.sort()
|
|
9
|
+
|
|
10
|
+
seek = 0
|
|
11
|
+
|
|
12
|
+
for r in right:
|
|
13
|
+
seek += abs(head - r)
|
|
14
|
+
head = r
|
|
15
|
+
|
|
16
|
+
if left:
|
|
17
|
+
seek += abs(head - left[0])
|
|
18
|
+
head = left[0]
|
|
19
|
+
|
|
20
|
+
for r in left:
|
|
21
|
+
seek += abs(head - r)
|
|
22
|
+
head = r
|
|
23
|
+
|
|
24
|
+
print("Total Seek Time =", seek)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
req = list(map(int, input("Enter requests: ").split()))
|
|
2
|
+
head = int(input("Enter initial head position: "))
|
|
3
|
+
disk_size = int(input("Enter disk size: "))
|
|
4
|
+
|
|
5
|
+
left = [x for x in req if x < head]
|
|
6
|
+
right = [x for x in req if x >= head]
|
|
7
|
+
|
|
8
|
+
left.sort()
|
|
9
|
+
right.sort()
|
|
10
|
+
|
|
11
|
+
seek = 0
|
|
12
|
+
|
|
13
|
+
for r in right:
|
|
14
|
+
seek += abs(head - r)
|
|
15
|
+
head = r
|
|
16
|
+
|
|
17
|
+
seek += abs(head - (disk_size - 1))
|
|
18
|
+
head = disk_size - 1
|
|
19
|
+
|
|
20
|
+
seek += disk_size - 1
|
|
21
|
+
head = 0
|
|
22
|
+
|
|
23
|
+
for r in left:
|
|
24
|
+
seek += abs(head - r)
|
|
25
|
+
head = r
|
|
26
|
+
|
|
27
|
+
print("Total Seek Time =", seek)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
n = int(input("Enter number of processes: "))
|
|
2
|
+
|
|
3
|
+
pid, at, bt = [], [], []
|
|
4
|
+
|
|
5
|
+
for i in range(n):
|
|
6
|
+
pid.append(input("Process ID: "))
|
|
7
|
+
at.append(int(input("Arrival Time: ")))
|
|
8
|
+
bt.append(int(input("Burst Time: ")))
|
|
9
|
+
|
|
10
|
+
# Sort by Arrival Time
|
|
11
|
+
p = sorted(zip(pid, at, bt), key=lambda x: x[1])
|
|
12
|
+
|
|
13
|
+
ct = []
|
|
14
|
+
time = 0
|
|
15
|
+
|
|
16
|
+
for _, a, b in p:
|
|
17
|
+
time = max(time, a) + b
|
|
18
|
+
ct.append(time)
|
|
19
|
+
|
|
20
|
+
tat = [ct[i] - p[i][1] for i in range(n)]
|
|
21
|
+
wt = [tat[i] - p[i][2] for i in range(n)]
|
|
22
|
+
|
|
23
|
+
print("\nPID\tTAT\tWT")
|
|
24
|
+
for i in range(n):
|
|
25
|
+
print(f"{p[i][0]}\t{tat[i]}\t{wt[i]}")
|
|
26
|
+
|
|
27
|
+
print("\nAverage TAT =", round(sum(tat) / n, 2))
|
|
28
|
+
print("Average WT =", round(sum(wt) / n, 2))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
blocks = list(map(int, input("Enter block sizes: ").split()))
|
|
2
|
+
processes = list(map(int, input("Enter process sizes: ").split()))
|
|
3
|
+
|
|
4
|
+
for i in range(len(processes)):
|
|
5
|
+
allocated = False
|
|
6
|
+
|
|
7
|
+
for j in range(len(blocks)):
|
|
8
|
+
if blocks[j] >= processes[i]:
|
|
9
|
+
print("Process", i + 1, "allocated to Block", j + 1)
|
|
10
|
+
blocks[j] -= processes[i]
|
|
11
|
+
allocated = True
|
|
12
|
+
break
|
|
13
|
+
|
|
14
|
+
if not allocated:
|
|
15
|
+
print("Process", i + 1, "not allocated")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
pages = list(map(int, input("Enter page reference string: ").split()))
|
|
2
|
+
frames = int(input("Enter number of frames: "))
|
|
3
|
+
|
|
4
|
+
memory = []
|
|
5
|
+
faults = 0
|
|
6
|
+
hits = 0
|
|
7
|
+
|
|
8
|
+
for page in pages:
|
|
9
|
+
|
|
10
|
+
if page in memory:
|
|
11
|
+
hits += 1
|
|
12
|
+
|
|
13
|
+
else:
|
|
14
|
+
faults += 1
|
|
15
|
+
|
|
16
|
+
if len(memory) < frames:
|
|
17
|
+
memory.append(page)
|
|
18
|
+
else:
|
|
19
|
+
memory.pop(0)
|
|
20
|
+
memory.append(page)
|
|
21
|
+
|
|
22
|
+
print(memory)
|
|
23
|
+
|
|
24
|
+
print("Page Faults =", faults)
|
|
25
|
+
print("Page Hits =", hits)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
pages = list(map(int, input("Enter page reference string: ").split()))
|
|
2
|
+
frames = int(input("Enter number of frames: "))
|
|
3
|
+
|
|
4
|
+
memory = []
|
|
5
|
+
freq = {}
|
|
6
|
+
|
|
7
|
+
faults = 0
|
|
8
|
+
hits = 0
|
|
9
|
+
|
|
10
|
+
for page in pages:
|
|
11
|
+
|
|
12
|
+
freq[page] = freq.get(page, 0) + 1
|
|
13
|
+
|
|
14
|
+
if page in memory:
|
|
15
|
+
hits += 1
|
|
16
|
+
|
|
17
|
+
else:
|
|
18
|
+
faults += 1
|
|
19
|
+
|
|
20
|
+
if len(memory) < frames:
|
|
21
|
+
memory.append(page)
|
|
22
|
+
|
|
23
|
+
else:
|
|
24
|
+
lfu = memory[0]
|
|
25
|
+
|
|
26
|
+
for p in memory:
|
|
27
|
+
if freq[p] < freq[lfu]:
|
|
28
|
+
lfu = p
|
|
29
|
+
|
|
30
|
+
memory.remove(lfu)
|
|
31
|
+
memory.append(page)
|
|
32
|
+
|
|
33
|
+
print(memory)
|
|
34
|
+
|
|
35
|
+
print("Page Faults =", faults)
|
|
36
|
+
print("Page Hits =", hits)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
req = list(map(int, input("Enter requests: ").split()))
|
|
2
|
+
head = int(input("Enter initial head position: "))
|
|
3
|
+
|
|
4
|
+
left = [x for x in req if x < head]
|
|
5
|
+
right = [x for x in req if x >= head]
|
|
6
|
+
|
|
7
|
+
left.sort()
|
|
8
|
+
right.sort()
|
|
9
|
+
|
|
10
|
+
seek = 0
|
|
11
|
+
|
|
12
|
+
for r in right:
|
|
13
|
+
seek += abs(head - r)
|
|
14
|
+
head = r
|
|
15
|
+
|
|
16
|
+
for r in reversed(left):
|
|
17
|
+
seek += abs(head - r)
|
|
18
|
+
head = r
|
|
19
|
+
|
|
20
|
+
print("Total Seek Time =", seek)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
pages = list(map(int, input("Enter page reference string: ").split()))
|
|
2
|
+
frames = int(input("Enter number of frames: "))
|
|
3
|
+
|
|
4
|
+
memory = []
|
|
5
|
+
faults = 0
|
|
6
|
+
hits = 0
|
|
7
|
+
|
|
8
|
+
for page in pages:
|
|
9
|
+
|
|
10
|
+
if page in memory:
|
|
11
|
+
hits += 1
|
|
12
|
+
memory.remove(page)
|
|
13
|
+
memory.append(page)
|
|
14
|
+
|
|
15
|
+
else:
|
|
16
|
+
faults += 1
|
|
17
|
+
|
|
18
|
+
if len(memory) < frames:
|
|
19
|
+
memory.append(page)
|
|
20
|
+
else:
|
|
21
|
+
memory.pop(0)
|
|
22
|
+
memory.append(page)
|
|
23
|
+
|
|
24
|
+
print(memory)
|
|
25
|
+
|
|
26
|
+
print("Page Faults =", faults)
|
|
27
|
+
print("Page Hits =", hits)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
blocks = list(map(int, input("Enter block sizes: ").split()))
|
|
2
|
+
processes = list(map(int, input("Enter process sizes: ").split()))
|
|
3
|
+
|
|
4
|
+
pos = 0
|
|
5
|
+
n = len(blocks)
|
|
6
|
+
|
|
7
|
+
for i in range(len(processes)):
|
|
8
|
+
allocated = False
|
|
9
|
+
count = 0
|
|
10
|
+
|
|
11
|
+
while count < n:
|
|
12
|
+
if blocks[pos] >= processes[i]:
|
|
13
|
+
print("Process", i + 1, "allocated to Block", pos + 1)
|
|
14
|
+
blocks[pos] -= processes[i]
|
|
15
|
+
allocated = True
|
|
16
|
+
break
|
|
17
|
+
|
|
18
|
+
pos = (pos + 1) % n
|
|
19
|
+
count += 1
|
|
20
|
+
|
|
21
|
+
if not allocated:
|
|
22
|
+
print("Process", i + 1, "not allocated")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
pages = list(map(int, input("Enter page reference string: ").split()))
|
|
2
|
+
frames = int(input("Enter number of frames: "))
|
|
3
|
+
|
|
4
|
+
memory = []
|
|
5
|
+
faults = 0
|
|
6
|
+
hits = 0
|
|
7
|
+
|
|
8
|
+
for i in range(len(pages)):
|
|
9
|
+
|
|
10
|
+
page = pages[i]
|
|
11
|
+
|
|
12
|
+
if page in memory:
|
|
13
|
+
hits += 1
|
|
14
|
+
|
|
15
|
+
else:
|
|
16
|
+
faults += 1
|
|
17
|
+
|
|
18
|
+
if len(memory) < frames:
|
|
19
|
+
memory.append(page)
|
|
20
|
+
|
|
21
|
+
else:
|
|
22
|
+
idx = -1
|
|
23
|
+
farthest = -1
|
|
24
|
+
|
|
25
|
+
for j in range(len(memory)):
|
|
26
|
+
|
|
27
|
+
if memory[j] not in pages[i+1:]:
|
|
28
|
+
idx = j
|
|
29
|
+
break
|
|
30
|
+
|
|
31
|
+
pos = pages[i+1:].index(memory[j])
|
|
32
|
+
|
|
33
|
+
if pos > farthest:
|
|
34
|
+
farthest = pos
|
|
35
|
+
idx = j
|
|
36
|
+
|
|
37
|
+
memory[idx] = page
|
|
38
|
+
|
|
39
|
+
print(memory)
|
|
40
|
+
|
|
41
|
+
print("Page Faults =", faults)
|
|
42
|
+
print("Page Hits =", hits)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
n = int(input("Enter number of processes: "))
|
|
2
|
+
|
|
3
|
+
pid = []
|
|
4
|
+
at = []
|
|
5
|
+
bt = []
|
|
6
|
+
pr = []
|
|
7
|
+
|
|
8
|
+
for i in range(n):
|
|
9
|
+
pid.append(input("Process ID: "))
|
|
10
|
+
at.append(int(input("Arrival Time: ")))
|
|
11
|
+
bt.append(int(input("Burst Time: ")))
|
|
12
|
+
pr.append(int(input("Priority: ")))
|
|
13
|
+
|
|
14
|
+
completed = [False] * n
|
|
15
|
+
tat = [0] * n
|
|
16
|
+
wt = [0] * n
|
|
17
|
+
|
|
18
|
+
time = 0
|
|
19
|
+
count = 0
|
|
20
|
+
|
|
21
|
+
while count < n:
|
|
22
|
+
|
|
23
|
+
idx = -1
|
|
24
|
+
highest = 9999
|
|
25
|
+
|
|
26
|
+
for i in range(n):
|
|
27
|
+
if at[i] <= time and not completed[i]:
|
|
28
|
+
if pr[i] < highest:
|
|
29
|
+
highest = pr[i]
|
|
30
|
+
idx = i
|
|
31
|
+
|
|
32
|
+
if idx == -1:
|
|
33
|
+
time += 1
|
|
34
|
+
continue
|
|
35
|
+
|
|
36
|
+
time += bt[idx]
|
|
37
|
+
|
|
38
|
+
tat[idx] = time - at[idx]
|
|
39
|
+
wt[idx] = tat[idx] - bt[idx]
|
|
40
|
+
|
|
41
|
+
completed[idx] = True
|
|
42
|
+
count += 1
|
|
43
|
+
|
|
44
|
+
print("\nPID\tTAT\tWT")
|
|
45
|
+
for i in range(n):
|
|
46
|
+
print(pid[i], "\t", tat[i], "\t", wt[i])
|
|
47
|
+
|
|
48
|
+
print("\nAverage TAT =", sum(tat)/n)
|
|
49
|
+
print("Average WT =", sum(wt)/n)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
n = int(input("Enter number of processes: "))
|
|
2
|
+
q = int(input("Enter Time Quantum: "))
|
|
3
|
+
|
|
4
|
+
pid = []
|
|
5
|
+
at = []
|
|
6
|
+
bt = []
|
|
7
|
+
|
|
8
|
+
for i in range(n):
|
|
9
|
+
pid.append(input("Process ID: "))
|
|
10
|
+
at.append(int(input("Arrival Time: ")))
|
|
11
|
+
bt.append(int(input("Burst Time: ")))
|
|
12
|
+
|
|
13
|
+
remaining = bt.copy()
|
|
14
|
+
|
|
15
|
+
tat = [0] * n
|
|
16
|
+
wt = [0] * n
|
|
17
|
+
|
|
18
|
+
time = 0
|
|
19
|
+
completed = 0
|
|
20
|
+
|
|
21
|
+
while completed < n:
|
|
22
|
+
|
|
23
|
+
done = True
|
|
24
|
+
|
|
25
|
+
for i in range(n):
|
|
26
|
+
|
|
27
|
+
if remaining[i] > 0 and at[i] <= time:
|
|
28
|
+
|
|
29
|
+
done = False
|
|
30
|
+
|
|
31
|
+
if remaining[i] > q:
|
|
32
|
+
time += q
|
|
33
|
+
remaining[i] -= q
|
|
34
|
+
|
|
35
|
+
else:
|
|
36
|
+
time += remaining[i]
|
|
37
|
+
|
|
38
|
+
tat[i] = time - at[i]
|
|
39
|
+
wt[i] = tat[i] - bt[i]
|
|
40
|
+
|
|
41
|
+
remaining[i] = 0
|
|
42
|
+
completed += 1
|
|
43
|
+
|
|
44
|
+
if done:
|
|
45
|
+
time += 1
|
|
46
|
+
|
|
47
|
+
print("\nPID\tTAT\tWT")
|
|
48
|
+
for i in range(n):
|
|
49
|
+
print(pid[i], "\t", tat[i], "\t", wt[i])
|
|
50
|
+
|
|
51
|
+
print("\nAverage TAT =", sum(tat)/n)
|
|
52
|
+
print("Average WT =", sum(wt)/n)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from threading import *
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
queue = []
|
|
5
|
+
max_size = 5
|
|
6
|
+
|
|
7
|
+
def customer():
|
|
8
|
+
for i in range(1, 11):
|
|
9
|
+
while len(queue) == max_size:
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
queue.append(i)
|
|
13
|
+
print("Customer", i, "arrived")
|
|
14
|
+
time.sleep(1)
|
|
15
|
+
|
|
16
|
+
def counter():
|
|
17
|
+
for i in range(1, 11):
|
|
18
|
+
while len(queue) == 0:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
c = queue.pop(0)
|
|
22
|
+
print("Serving Customer", c)
|
|
23
|
+
time.sleep(2)
|
|
24
|
+
|
|
25
|
+
t1 = Thread(target=customer)
|
|
26
|
+
t2 = Thread(target=counter)
|
|
27
|
+
|
|
28
|
+
t1.start()
|
|
29
|
+
t2.start()
|
|
30
|
+
|
|
31
|
+
t1.join()
|
|
32
|
+
t2.join()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
req = list(map(int, input("Enter requests: ").split()))
|
|
2
|
+
head = int(input("Enter initial head position: "))
|
|
3
|
+
disk_size = int(input("Enter disk size: "))
|
|
4
|
+
|
|
5
|
+
left = [x for x in req if x < head]
|
|
6
|
+
right = [x for x in req if x >= head]
|
|
7
|
+
|
|
8
|
+
left.sort()
|
|
9
|
+
right.sort()
|
|
10
|
+
|
|
11
|
+
seek = 0
|
|
12
|
+
|
|
13
|
+
for r in right:
|
|
14
|
+
seek += abs(head - r)
|
|
15
|
+
head = r
|
|
16
|
+
|
|
17
|
+
seek += abs(head - (disk_size - 1))
|
|
18
|
+
head = disk_size - 1
|
|
19
|
+
|
|
20
|
+
for r in reversed(left):
|
|
21
|
+
seek += abs(head - r)
|
|
22
|
+
head = r
|
|
23
|
+
|
|
24
|
+
print("Total Seek Time =", seek)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
n = int(input("Enter number of processes: "))
|
|
2
|
+
|
|
3
|
+
pid = []
|
|
4
|
+
at = []
|
|
5
|
+
bt = []
|
|
6
|
+
|
|
7
|
+
for i in range(n):
|
|
8
|
+
pid.append(input("Process ID: "))
|
|
9
|
+
at.append(int(input("Arrival Time: ")))
|
|
10
|
+
bt.append(int(input("Burst Time: ")))
|
|
11
|
+
|
|
12
|
+
completed = [False] * n
|
|
13
|
+
tat = [0] * n
|
|
14
|
+
wt = [0] * n
|
|
15
|
+
|
|
16
|
+
time = 0
|
|
17
|
+
count = 0
|
|
18
|
+
|
|
19
|
+
while count < n:
|
|
20
|
+
|
|
21
|
+
idx = -1
|
|
22
|
+
min_bt = 9999
|
|
23
|
+
|
|
24
|
+
for i in range(n):
|
|
25
|
+
if at[i] <= time and not completed[i]:
|
|
26
|
+
if bt[i] < min_bt:
|
|
27
|
+
min_bt = bt[i]
|
|
28
|
+
idx = i
|
|
29
|
+
|
|
30
|
+
if idx == -1:
|
|
31
|
+
time += 1
|
|
32
|
+
continue
|
|
33
|
+
|
|
34
|
+
time += bt[idx]
|
|
35
|
+
|
|
36
|
+
tat[idx] = time - at[idx]
|
|
37
|
+
wt[idx] = tat[idx] - bt[idx]
|
|
38
|
+
|
|
39
|
+
completed[idx] = True
|
|
40
|
+
count += 1
|
|
41
|
+
|
|
42
|
+
print("\nPID\tTAT\tWT")
|
|
43
|
+
for i in range(n):
|
|
44
|
+
print(pid[i], "\t", tat[i], "\t", wt[i])
|
|
45
|
+
|
|
46
|
+
print("\nAverage TAT =", sum(tat)/n)
|
|
47
|
+
print("Average WT =", sum(wt)/n)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
n = int(input("Enter number of processes: "))
|
|
2
|
+
|
|
3
|
+
pid = []
|
|
4
|
+
at = []
|
|
5
|
+
bt = []
|
|
6
|
+
|
|
7
|
+
for i in range(n):
|
|
8
|
+
pid.append(input("Process ID: "))
|
|
9
|
+
at.append(int(input("Arrival Time: ")))
|
|
10
|
+
bt.append(int(input("Burst Time: ")))
|
|
11
|
+
|
|
12
|
+
remaining = bt.copy()
|
|
13
|
+
|
|
14
|
+
tat = [0] * n
|
|
15
|
+
wt = [0] * n
|
|
16
|
+
|
|
17
|
+
time = 0
|
|
18
|
+
completed = 0
|
|
19
|
+
|
|
20
|
+
while completed < n:
|
|
21
|
+
|
|
22
|
+
idx = -1
|
|
23
|
+
shortest = 9999
|
|
24
|
+
|
|
25
|
+
for i in range(n):
|
|
26
|
+
if at[i] <= time and remaining[i] > 0:
|
|
27
|
+
if remaining[i] < shortest:
|
|
28
|
+
shortest = remaining[i]
|
|
29
|
+
idx = i
|
|
30
|
+
|
|
31
|
+
if idx == -1:
|
|
32
|
+
time += 1
|
|
33
|
+
continue
|
|
34
|
+
|
|
35
|
+
remaining[idx] -= 1
|
|
36
|
+
time += 1
|
|
37
|
+
|
|
38
|
+
if remaining[idx] == 0:
|
|
39
|
+
completed += 1
|
|
40
|
+
|
|
41
|
+
tat[idx] = time - at[idx]
|
|
42
|
+
wt[idx] = tat[idx] - bt[idx]
|
|
43
|
+
|
|
44
|
+
print("\nPID\tTAT\tWT")
|
|
45
|
+
for i in range(n):
|
|
46
|
+
print(pid[i], "\t", tat[i], "\t", wt[i])
|
|
47
|
+
|
|
48
|
+
print("\nAverage TAT =", sum(tat)/n)
|
|
49
|
+
print("Average WT =", sum(wt)/n)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
req = list(map(int, input("Enter requests: ").split()))
|
|
2
|
+
head = int(input("Enter initial head position: "))
|
|
3
|
+
|
|
4
|
+
seek = 0
|
|
5
|
+
|
|
6
|
+
while req:
|
|
7
|
+
nearest = min(req, key=lambda x: abs(head - x))
|
|
8
|
+
|
|
9
|
+
seek += abs(head - nearest)
|
|
10
|
+
head = nearest
|
|
11
|
+
|
|
12
|
+
req.remove(nearest)
|
|
13
|
+
|
|
14
|
+
print("Total Seek Time =", seek)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
blocks = list(map(int, input("Enter block sizes: ").split()))
|
|
2
|
+
processes = list(map(int, input("Enter process sizes: ").split()))
|
|
3
|
+
|
|
4
|
+
for i in range(len(processes)):
|
|
5
|
+
worst = -1
|
|
6
|
+
|
|
7
|
+
for j in range(len(blocks)):
|
|
8
|
+
if blocks[j] >= processes[i]:
|
|
9
|
+
if worst == -1 or blocks[j] > blocks[worst]:
|
|
10
|
+
worst = j
|
|
11
|
+
|
|
12
|
+
if worst != -1:
|
|
13
|
+
print("Process", i + 1, "allocated to Block", worst + 1)
|
|
14
|
+
blocks[worst] -= processes[i]
|
|
15
|
+
else:
|
|
16
|
+
print("Process", i + 1, "not allocated")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
oslabcode/__init__.py,sha256=0y91PW-fcytGzZxMWcdcVL1uY8YfJz4Qb4CVpB1hAXg,21
|
|
2
|
+
oslabcode/cli.py,sha256=ApPk2pfg24qYX8YLjGLs6abpWNz8cf9gXnZxtg3vijw,2117
|
|
3
|
+
oslabcode/templates/BF.py,sha256=gq9LaTtpoiKlr2Loz_moM0WYKm1zKbIpyNKZpUftnYM,522
|
|
4
|
+
oslabcode/templates/Banker.py,sha256=PUx7UHuuF7Bb2N3SzeJU2JYPUDFvDsWVWycRL5FNAKI,1341
|
|
5
|
+
oslabcode/templates/CLOOK.py,sha256=Qqj3g-WzfJs0JTAV23fO8r9T3dz8MmxXx0SUQS2IXPE,446
|
|
6
|
+
oslabcode/templates/CSCAN.py,sha256=ut8G33kpv3wymQ7IZ-z6uTy0xdrOAeLSB8uKAbgnz2Q,522
|
|
7
|
+
oslabcode/templates/FCFS_DS.py,sha256=uY2xtXafpnlCOof_PRdv0jY09mVWXecMxi-a3CKe32M,213
|
|
8
|
+
oslabcode/templates/FCFS_PS.py,sha256=cRBz9ECdcnccnVD-2jRBJP70oc3DXXVJWngqt0yghyk,667
|
|
9
|
+
oslabcode/templates/FF.py,sha256=J1ZoPtk1pddgCKz6bbzrJkF4dwv5UMffZGdeXfP7GQg,491
|
|
10
|
+
oslabcode/templates/FIFO.py,sha256=OD9PGrPkvFfn4x6S0oXIoeBAasggJNybNjPgHlMtcPg,484
|
|
11
|
+
oslabcode/templates/LFU.py,sha256=0CUyX_UlMCqs798yX2qA7UfLQ9FJRqdnOWRYlZVH9BU,679
|
|
12
|
+
oslabcode/templates/LOOK.py,sha256=L-qTaAGRJEsHpj4-6yhpx7spggkmHyxIUJxlFUUDk9w,391
|
|
13
|
+
oslabcode/templates/LRU.py,sha256=n5DjcXp1NFVcaw5J_q91WHs4G2stkaUlUk1c8tOJHcE,542
|
|
14
|
+
oslabcode/templates/NF.py,sha256=QuS4L_BdArcyOy0D_7RRWnQm4G7jiy_lQrsg1tx4H-U,579
|
|
15
|
+
oslabcode/templates/Optimal.py,sha256=rEsUL1VgkhWz6Jgo2ojmFy971UjHUT7wrF0DE8r5cbg,850
|
|
16
|
+
oslabcode/templates/Priority.py,sha256=qh81yw0fZHRDE51tsw82MiW2yU1xicAESkKL67qAMrE,934
|
|
17
|
+
oslabcode/templates/RR.py,sha256=uMCKxzfgfBGqzV3vSbKB-6SPTtbaxi2uNOtycTRKNg8,1002
|
|
18
|
+
oslabcode/templates/SC.py,sha256=wHru8vTkMbmIUPxVV0V2Fo2f41KJYp4u8HicvJ4Abqk,555
|
|
19
|
+
oslabcode/templates/SCAN.py,sha256=AvpZ6215wk15HoQ7_nP8oxMFasziomNdZmmdN_-H71Y,497
|
|
20
|
+
oslabcode/templates/SJF.py,sha256=q6OHD40rn4ICFRH-ytPQWeJTDffkaej2VbbC4uYfsdk,881
|
|
21
|
+
oslabcode/templates/SRTF.py,sha256=U6GenEd-r5z8nJrZMme8lYhwqDqAYPYytKr8oQvRHdY,946
|
|
22
|
+
oslabcode/templates/SSTF.py,sha256=YNWcWm4sogc9eTK-i7znQdT3fuk_-PMnv-kPkEzpzrM,304
|
|
23
|
+
oslabcode/templates/WF.py,sha256=VZLrbT2i-8j9H_RySeE3X3ahkmyGwBuw-Sbe2vi_RbI,529
|
|
24
|
+
oslabcode-1.0.0.dist-info/METADATA,sha256=J_qy5oy1wLJjo5BlMw4f0te9aO3iLlE-cmHta6VDou4,112
|
|
25
|
+
oslabcode-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
26
|
+
oslabcode-1.0.0.dist-info/entry_points.txt,sha256=gM6nkAQUkTL75fUs0VDX_sqJ9AdW-wZysOkHYI39b3s,49
|
|
27
|
+
oslabcode-1.0.0.dist-info/top_level.txt,sha256=Ijo5NZgTe0tadQfi1ao35-Aq4GnVIUVOq2czB2arPCI,10
|
|
28
|
+
oslabcode-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
oslabcode
|