3
1
SystemsProgrammingAndOperat.../Codes/Python version/Assignment-A6 (Memory placement)/First Fit.py

23 lines
745 B
Python
Raw Permalink Normal View History

def first_fit(memory_blocks, process_sizes):
allocation = [-1] * len(process_sizes)
for i in range(len(process_sizes)):
for j in range(len(memory_blocks)):
if memory_blocks[j] >= process_sizes[i]:
allocation[i] = j
memory_blocks[j] -= process_sizes[i]
break
print("\nFirst Fit Allocation:")
for i in range(len(process_sizes)):
if allocation[i] != -1:
print(f"Process {i+1} allocated to Block {allocation[i]+1}")
else:
print(f"Process {i+1} not allocated")
# Example Memory Blocks and Process Sizes
memory_blocks = [100, 500, 200, 300, 600]
process_sizes = [212, 417, 112, 426]
first_fit(memory_blocks, process_sizes)