Question: I'm trying to implement simulation of CPU Scheduling Round Robin. I have the code below, but it needs to read the input from a txt

I'm trying to implement simulation of CPU Scheduling Round Robin. I have the code below, but it needs to read the input from a txt file and output the results to a different txt file(preferrably in the same directory as the code. Here is the details of how it works, followed by the code.

Input File:

The first line has a space-separated list of scheduling algorithm names to run (any combination of the four names given above). The second line has a single integer representing the number of processes in the file. The rest of the file has one line per process with the following information:

Process number Arrival Time CPU burst time Priority

If multiple processes have the same arrival time, your scheduling algorithm should assume that there are negligibly small differences in arrival times with the processes arriving in the order they appear in the file. For priority scheduling, assume that smaller numbers indicate higher priorities. Non-priority algorithms will simply ignore the priority field.

Output File:

The output file will have the scheduling results for each of the algorithms listed in the input file. There should be one line for each CPU assignment (one line for each vertical line in the Gantt chart). Each line should have two numbers: one indicating the time point and one indicating the process number that got the CPU at that point. The last line for each scheduling algorithm should have the average waiting time.

Example: As shown in the example below, when the algorithm is RR, there should be an integer parameter next to the algorithms name specifying the length of the time quantum:

RR 4

3

1 0 24 1

2 0 3 1

3 0 3 1

Output 1

RR

1

4 2

7 3

10 1

14 1

18 1

22 1

26 1

AVG Waiting Time: 5.67

Here is the code I have so far:

#include int main() { int count,j,n,time,remain,flag=0,time_quantum; int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; printf("Enter Total Process:\t "); scanf("%d",&n); remain=n; for(count=0;count0) { time+=rt[count]; rt[count]=0; flag=1; } else if(rt[count]>0) { rt[count]-=time_quantum; time+=time_quantum; } if(rt[count]==0 && flag==1) { remain--; printf("P[%d]\t|\t%d\t|\t%d ",count+1,time-at[count],time-at[count]-bt[count]); wait_time+=time-at[count]-bt[count]; turnaround_time+=time-at[count]; flag=0; } if(count==n-1) count=0; else if(at[count+1]<=time) count++; else count=0; } printf(" Average Waiting Time= %f ",wait_time*1.0/n); printf("Avg Turnaround Time = %f",turnaround_time*1.0/n); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!