0% found this document useful (0 votes)
5 views2 pages

FCFS and SJF Task Scheduling Analysis

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

FCFS and SJF Task Scheduling Analysis

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

FCFS:

tasks = {

"t1":100000, "t2":70000, "t3":5000, "t4":1000, "t5":3000,

"t6":10000, "t7":90000, "t8":100000, "t9":15000, "t10":1000,

"t11":2000, "t12":4000, "t13":20000, "t14":25000, "t15":80000

vms = ["VM1","VM2","VM3","VM4","VM5","VM6"]

mips = {"VM1":500,"VM2":500,"VM3":1500,"VM4":1500,"VM5":2500,"VM6":2500}

vm_wait = {vm:0 for vm in vms}

vm_max = {vm:0 for vm in vms}

assignments = {vm:[] for vm in vms}

for i,(t,l) in enumerate([Link]()):

vm = vms[i % len(vms)]

et = l/mips[vm]

wait = vm_wait[vm]

if wait>vm_max[vm]:

vm_max[vm]=wait

vm_wait[vm]+=et

assignments[vm].append(t)

total=sum(vm_max.values())

avg=total/len(vms)

for vm in vms:

print(f"{vm} = {assignments[vm]}")

print("Total Waiting Time =", round(total,2))

print("Average Waiting Time =", round(avg,2))


SJF:
tasks = {

"t1":100000,"t2":70000,"t3":5000,"t4":1000,"t5":3000,

"t6":10000,"t7":90000,"t8":100000,"t9":15000,"t10":1000,

"t11":2000,"t12":4000,"t13":20000,"t14":25000,"t15":80000

vms = ["VM1","VM2","VM3","VM4","VM5","VM6"]

mips = {"VM1":500,"VM2":500,"VM3":1500,"VM4":1500,"VM5":2500,"VM6":2500}

tasks = sorted([Link](), key=lambda x:x[1])

wait = {vm:0 for vm in vms}

max_wait = {vm:0 for vm in vms}

assign = {vm:[] for vm in vms}

for i,(t,l) in enumerate(tasks):

vm = vms[i % len(vms)]

assign[vm].append(t)

max_wait[vm] = max(max_wait[vm], wait[vm])

wait[vm] += l/mips[vm]

total = sum(max_wait.values())

avg = total/len(vms)

for vm in vms: print(vm, "=", assign[vm])

print("Total Waiting Time =", round(total,2))

print("Average Waiting Time =", round(avg,2))

You might also like