# Pastebin UUifjbYS import time class job: def __init__(self, id, cpuReq, status): self.id = id self.cpuReq = cpuReq self.active = status def __str__(self): return "jobid: %s | Size: %s | Active: %s " % (self.id, self.cpuReq, self.active) class scheduler: def __init__(self): print("starting scheduler") print(">>>>>>>>>>>>>>") def getShortestJob(self, runQueue): shortestjob= runQueue[0] i=0; for j in runQueue: if j.cpuReq < shortestjob.cpuReq and j.active==0: shortestjob=runQueue[i] i =i+1 return shortestjob def schedule(self, runQueue): cpuCycle=0 currentIndex=0 while runQueue: shortestJob=self.getShortestJob(runQueue) print("The shortest Job selected is: ", shortestJob) print("") print("-------starting execution : job id ", shortestJob.id,"-------------") shortestJob.active=1 while shortestJob.cpuReq >= 1: cpuCycle= cpuCycle + 1 shortestJob.cpuReq = shortestJob.cpuReq - 1 print ("CPUCycle #", cpuCycle) print (shortestJob) time.sleep(1) print("-------finished execution : job id ", shortestJob.id,"--------------") print("-------chaning status : job id ", shortestJob.id," --------") shortestJob.active=0 print(shortestJob) print("-------removing job : job id ", shortestJob.id," from the queue--------") runQueue.remove(shortestJob) p1=job(2, 2 ,0) p2=job(3, 3 ,0) p3=job(1, 1,0) p4=job(4, 4,0) p5=job(5, 5 ,0) runQueue=list() runQueue.append(p1) runQueue.append(p2) runQueue.append(p3) runQueue.append(p4) runQueue.append(p5) print (p1) print (p2) print (p3) print (p4) print (p5) sch=scheduler() sch.schedule(runQueue)