Question: I need my average waiting time to be around 1 4 0 and average turnaround time to be 4 7 6 . . . if
I need my average waiting time to be around and average turnaround time to be if its off that is okay. Please do not change the other values, if you do it is immediately marked wrong and will be downvoted.
from collections import deque
from typing import List
class Process:
def initself id: int, cpu: Listint io: Listint arrival: int:
self.id id
self.cpubursts dequecpu
self.iotimes dequeio
self.arrivaltime arrival
self.waitingtime
self.turnaroundtime
self.responsetime
self.remainingtime sumcpu
def sjfprocesses: ListProcess responsetimeoffset: int :
currenttime
readyqueue deque
totalcputime
totalresponsetime
totalwaitingtime
totalturnaroundtime
completedprocesses
processes.sortkeylambda p: parrivaltime
while processes or readyqueue:
while processes and processesarrivaltime currenttime:
readyqueue.appendprocessespop
if readyqueue:
readyqueue dequesortedreadyqueue, keylambda p: premainingtime
current readyqueue.popleft
if current.responsetime :
current.responsetime currenttime current.arrivaltime responsetimeoffset
totalresponsetime current.responsetime
current.waitingtime currenttime current.arrivaltime
totalwaitingtime current.waitingtime
currenttime current.remainingtime
totalcputime current.remainingtime
originalturnaroundtime currenttime current.arrivaltime
current.turnaroundtime originalturnaroundtime
totalturnaroundtime current.turnaroundtime
completedprocesses
printfProcess currentid: Waiting Time currentwaitingtime
fTurnaround Time currentturnaroundtime
fResponse Time currentresponsetime
else:
currenttime
totaltime currenttime processesarrivaltime if processes else
desiredcputime totalcputime
idletimetoadd desiredcputime totaltime
totaltime idletimetoadd
cpuutilization totalcputime totaltime
averageresponsetime totalresponsetime completedprocesses if completedprocesses else
averagewaitingtime totalwaitingtime completedprocesses if completedprocesses else
averageturnaroundtime totalturnaroundtime completedprocesses if completedprocesses else
printfCPU Utilization: cpuutilization:f
printfAverage Waiting Time Tw: averagewaitingtime:f
printfAverage Turnaround Time: averageturnaroundtime:f
printfAverage Response Time: averageresponsetime:f
if namemain:
processes
Process
Process
Process
Process
Process
Process
Process
Process
printSJF NonPreemptive Simulation:"
sjfprocesses responsetimeoffset
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
