Question: Python Change the code further to store the execution order of the processes in the order [ ] array. Print the execution order and number
Python
Change the code further to store the execution order of the processes in the order array. Print the execution order and number of context switch.
def roundrobinschedulingprocesses quantum:
n lenprocesses
rembursttimes p for p in processes
waitingtime n
turnaroundtime n
t # Current time
order # To track the order of execution
while anyrembursttimesi for i in rangen:
for i in rangen:
if rembursttimesi:
processexecuted False
if rembursttimesi quantum:
# Track the execution order
t quantum
rembursttimesi quantum
processexecuted True
order.appendprocessesi quantum
else:
# Track the execution order
t rembursttimesi
waitingtimei t processesi
order.appendprocessesi rembursttimesi
rembursttimesi
processexecuted True
if processexecuted:
# Print a message "Process executed for units"
printfProcess processesi executed for order units"
# Calculate turnaround time
for i in rangen:
turnaroundtimei processesi waitingtimei
# Calculate average times
avgwaiting sumwaitingtime n
avgturnaround sumturnaroundtime n
# Display results
print
Process IDtBurst TimetWaiting TimetTurnaround Time"
for i in rangen:
printfprocessesittprocessesittwaitingtimeittturnaroundtimei
printf
Average Waiting Time: avgwaiting
printfAverage Turnaround Time: avgturnaround
# Print execution order and number of context switch
print
Execution Order Process ID Time Units:
for p in order:
printfProcess p executed for p units"
if namemain:
# List of processes processid bursttime
# Assuming same initial arrival time for all process
processes
while True:
# Ask user to input time quantum
quantum intinputEnter time quantum:
roundrobinschedulingprocesses quantum
# Ask user whether to continue or not Y to repeat, exit otherwise
endq inputDo you want to continue? Y to repeat, exit otherwise
if endq Y:
break
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
