Question: I have this code. Can you fix the main, computStat, ShortestRemainingSort, and RoundRobinSort function? This is the batchfile- batchfile for this assignment located in the
I have this code. Can you fix the main, computStat, ShortestRemainingSort, and RoundRobinSort function?
This is the batchfile-





batchfile for this assignment located in the repo. Each line of the batchfile contains 4 comma separated values. They are: PID, Arrival Time, Burst Time (also known as execution time). PID is the process id. Arrival time is the time since the process arrived in the ready queue. Burst time is the amount of time required to fully execute the process on the CPU. Let's look at a simplified example of the batchfile: 1,3,7,2,0,0,9,10,2050412 n=len(array) burst =[] for i in range(n) : burst. append (array [i] [2]) arrival =[] for i in range (n) : arrival, append (array [i] [1]) avg =0 avgt=0 turnaround =[] wait =[] if (sys.argv[2] == "ShortestRemaining"): order , completion = ShortestRemainingSort ( array ) print("PID ORDER OF EXECUTION: (n ) for g in range(len(order)): print (order [g][0]) avgw, avgt , wait , turnaround = Computestat (completion, arrival, burst) print(" \ nAverage Process Turnaround Time:", avgt) print("Average Process Wait Time:", avgw) elif (sys. argv[2]== "RoundRobinSort"): order , completion = RoundRobinSort (array) print("PID ORDER OF EXECUTION: (n) for g in range(len(order)): print (order [g][0]) avgw, avgt , wait , turnaround = Computestat (completion, arrival, burst) print(" Average Process Turnaround Time:", avgt) print("Average Process Wait Time:", avgw) else : print("Unidentified sorting algorithm. Please input either ShortestRemaining or RoundRobinSort.") return 1 e: print("Please provide command line arguments when running. python3 batchSchedulingComparison.py batchfile.txt RoundRobinSort") return 1 RoundRobinSort(batchFileData) Parameters: accepts all of the batchFileData from the batchfile opened in main Returns: (1)a list (or other data structure) of the time each process is completed at, and (2) a list (or other data structure) containing the PID of the processes in the order the algorithm sorted them by. We will use a quanta of 10 for this portion If the command line argument states that the user wants to process batch jobs using RoundRobin, then this function will be called. The data from the batchfile should be passed in and sorted by arrival (again, there are many ways to do this). The basic algorithm can be summarized as: At the end of each quanta (10): Check what processes are available for execution. If multiple processes are available, choose the one with the lower PID (lower PID usually indicates higher importance.) Execute the process with the lower PID for the full quanta. After a quanta has passed, execute the next process in the ready queue at that time. Repeat execution for full quanta until all processes have been fully run Finally, print the PID values of the processes in the order that they will be executed by the algorithm, the average process waiting time, and average process turn around time. Using the example batchfile, the input would look like this: python 3 batchSchedulingComparison.py pa2_batchfile.txt RoundRobin And the output (FROM MAIN BASED ON YOUR RETURNED VALUES) would be: PID ORDER OF EXECUTION : 1 3 7 2 1 3 2 3 3 3 Average Process Turnaround Time: 47.75 Average Process Wait Time: 26.25 RoundRobinSort(batchFileData): queue =[] \# queue of jobs to be executed current_time =0 \# current time in the scheduling algorithm waiting_times ={}# dictionary to store waiting times for each job completion_times ={}# dictionary to store completion times for each job \# add first job to the queue queue. append (jobs [0]) while len(queue) > 0 : \# get next job from the queue job= queue. pop(0) \# calculate waiting time for the job if job[0] not in waiting_times: waiting_times [job[0]]= current_time job[1] \# execute the job for the specified quantum or until completion if job [2] > quantum: current time += quantum job=(job[0], current_time, job[2] - quantum) queue. append ( job ) else: current_time += job [2] completion_times [job[0]]= current_time \# add new jobs to the queue that have arrived while current job was executing for j in jobs: if j[1]> current_time: break if j not in queue and j[0] not in completion_times: queue. append (j) \# sort the queue by job ID queue. sort(key= lambda x:x[0]) \# calculate waiting time for any remaining jobs for j in jobs: if j[0] not in completion_times: waiting times [j[0]]=0 \# calculate completion time and waiting time for each job results =[] for j in jobs: results. append ((j[0],j[1],j[2], completion_times [j[0]], waiting_times [j[0]])) return results
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
