Question: My code is written but need to meet the requirement to have it read from a file. Please fix the folling .c files to meet

My code is written but need to meet the requirement to have it read from a file. Please fix the folling .c files to meet the requirements. In this assignment, you will be writing a program that reads a list of process start times and durations from stdin. That list will be used four times to run through the following CPU scheduling algorithms: First Come, First Served, Shortest Job First, Shortest Remaining Time First, Round Robin. Your program will show three statistics; the average process response time, the average process wait time, and the average process turnaround time for each scheduling algorithm. The time quantum for the Round Robin scheduler is 100ms. Your program only needs to work with a maximum of 100 processes. Hints: Don't overcomplicate this assignment. Keep your process start times in one integer array, your burst times in another integer array, and then refer to those processes via other arrays. Make four functions, one for each scheduling mechanism. Pass the input data to each function as a parameter. Do not modify your original arrays as you will be reusing the data in those arrays multiple times. This program is simply an adder of process run times to a clock. Use the value of the clock to determine if new processes need to be added to your queue. Some students have tried to write a program that increments the clock one tick at a time. This is the difficult way to do it and is also incorrect. The context switch cost is negligible and is not figured into this assignment. Please make it so my code reads from a processlist.txt file and compiles Output: With this process list, the output of your program should look like this: Please note that each average displayed shows a result up to two decimal places. Code below:

FCFSScheduling.c

#include // main function definition int main() { // To store number of process int numberOfProcess; // Array to store burst time, waiting time ,turn around time int burstTime[20], waitingTime[20], turnAroundTime[20]; int avgWaitingTime = 0, avgTAT = 0, c, d; printf("Enter total number of processes(maximum 20):"); scanf("%d",&numberOfProcess);

printf(" Enter Process Burst Time "); for(c = 0; c < numberOfProcess; c++) { printf("Process[%d]:", c + 1); scanf("%d", &burstTime[c]); }// End of for loop // Waiting time for first process is 0 waitingTime[0] = 0;

// Calculating waiting time for(c = 1; c < numberOfProcess; c++) { waitingTime[c] = 0; for(d = 0; d < c; d++) waitingTime[c] += burstTime[d]; }// End of for loop

printf(" Process\t\tBurst Time\tWaiting Time\tTurnaround Time");

// Calculating turnaround time for(c = 0; c < numberOfProcess; c++) { turnAroundTime[c] = burstTime[c] + waitingTime[c]; avgWaitingTime += waitingTime[c]; avgTAT += turnAroundTime[c]; printf(" P[%d]\t\t%d\t\t%d\t\t%d", c + 1, burstTime[c], waitingTime[c], turnAroundTime[c]); }// End of for loop

avgWaitingTime /= c; avgTAT /= c; printf(" Average Waiting Time: %d", avgWaitingTime); printf(" Average Turnaround Time: %d",avgTAT);

return 0; }// End of main

RRScheduling.c

#include // main function definition int main() {

int counter, j, numberOfProcess, time, remainingProcess, flag = 0, timeQuantum;

int waitTime = 0, turnAroundTime = 0, ArivalTime[20], burtTime[20], runTime[20]; // Accepts number of processes from the user printf("Enter Total Process:\t "); scanf("%d", &numberOfProcess); // Assigns number of process to remaining process remainingProcess = numberOfProcess; // Loops till number of processes for(counter = 0; counter < numberOfProcess; counter++) { // Accepts arrival time and burst time for each process printf("Enter Arrival Time and Burst Time for Process Process Number %d :", counter + 1); scanf("%d", &ArivalTime[counter]); scanf("%d", &burtTime[counter]); runTime[counter] = burtTime[counter]; }// End of for loop // Accept time quantum from the user printf("Enter Time Quantum:\t"); scanf("%d", &timeQuantum);

printf(" Process\t|Turnaround Time|Waiting Time "); // Loops till remaining process for(time = 0, counter = 0; remainingProcess != 0;) { // Checks if the runtime of counter index position value is less than or equals to time quantum // and run time counter index position is greater than zero if(runTime[counter] <= timeQuantum && runTime[counter] > 0) { // Increase the time by runtime count index position value time += runTime[counter]; // Set the runtime counter index position value to zero for process finish runTime[counter] = 0; // Set the flag to one flag = 1; }// End of if condition // Otherwise checks if run time of counter index position value is greater than zero else if(runTime[counter] > 0) { // Subtract quantum from run time counter index position value runTime[counter] -= timeQuantum; // Increase the time by time quantum time += timeQuantum; }// End of else if condition // Checks if the run time counter index position value is zero and flag is one if(runTime[counter] == 0 && flag == 1) { // Decrease the remaining process by one remainingProcess--; // Displays process information printf("Process[%d]\t | \t%d\t | \t%d ",counter + 1, time - ArivalTime[counter], time - ArivalTime[counter] - burtTime[counter]); // Calculates waiting time for each process waitTime += time - ArivalTime[counter] - burtTime[counter]; // Calculates turn around time for each process turnAroundTime += time - ArivalTime[counter]; // Set the flag to zero for next process flag = 0; }// End of if condition

// Checks if counter value is equals to number of process minus one if(counter == numberOfProcess - 1) // Set the counter value to zero counter = 0; // Otherwise checks if the arrival time of next counter position value is less than or equals to time else if(ArivalTime[counter + 1] <= time) // Increase the counter value by one counter++; // Otherwise else // Set the counter value to zero counter = 0; }// End of for loop // Displays average waiting and turn around time printf(" Average Waiting Time= %.2f", waitTime * 1.0 / numberOfProcess); printf(" Avg Turnaround Time = %.2f", turnAroundTime * 1.0 / numberOfProcess);

return 0; }// End of main function

SJFScheduling.c

#include

int main() { // To store number of process int numberOfProcess; // Array to store burst time, waiting time ,turn around time int burstTime[20], waitingTime[20], turnAroundTime[20], process[20]; // Loop variables int c, d; int total = 0, pos, temp; float avgWaitingTime = 0, avgTAT = 0; printf("Enter number of process:"); scanf("%d",&numberOfProcess);

printf(" Enter Burst Time: "); // Loops till number of processes to accept burst time for(c = 0; c < numberOfProcess; c++) { // Accepts burst time for each process printf("Process[%d]: ", c + 1); scanf("%d",&burstTime[c]); // Contains process number process[c] = c + 1; }// End of for loop

// Sorting burst time in ascending order using selection sort // Loops till number of process for(c = 0; c < numberOfProcess; c++) { // To store the current index position pos = c; for(d = c + 1; d < numberOfProcess; d++) { // Checks burst time of d index position value with burst index position of pos index position value // If less then update the pos to d value if(burstTime[d] < burstTime[pos]) pos = d; }// End of inner for loop // Swapping process for the burst time temp = burstTime[c]; burstTime[c] = burstTime[pos]; burstTime[pos] = temp; // Swapping process for the process number temp = process[c]; process[c] = process[pos]; process[pos] = temp; }// End of outer for loop // Waiting time for first process will be zero waitingTime[0] = 0;

// Calculate waiting time for all the processes // Loops till number of processes for(c = 1; c < numberOfProcess; c++) { waitingTime[c] = 0; // Loops till c value for(d = 0; d < c; d++) // Calculates waiting time by adding burst time waitingTime[c] += burstTime[d]; // Calculates total waiting time total += waitingTime[c]; }// End of for loop // Calculates Average waiting time avgWaitingTime = (float)total / numberOfProcess; total = 0;

printf(" Process\t Burst Time \tWaiting Time\tTurnaround Time"); // Loops till number of processes for(c = 0; c < numberOfProcess; c++) { // Calculate turnaround time turnAroundTime[c] = burstTime[c] + waitingTime[c]; total += turnAroundTime[c]; printf(" p%d\t\t %d\t\t %d\t\t\t%d",process[c], burstTime[c], waitingTime[c],turnAroundTime[c]); }// End of for loop // Calculates average turnaround time avgTAT = (float)total / numberOfProcess;

printf(" Average Waiting Time = %.2f", avgWaitingTime); printf(" Average Turnaround Time = %.2f ", avgTAT); }// End of main

SRTFScheduling.c

/*The function is SRTF with the following prototype

void SRTF(number_of_processes,pointer_to_array_of_arrival_time,pointer_to_array_of_burst_time)

A linked list is used to store the Gantt Chart.*/

#include #include

typedef struct GanttNode{ int start; int end; int processNumber; struct GanttNode *link; }ganttNode;

ganttNode *addNode(ganttNode *head,int process,int startTime,int endTime){ ganttNode *endNode,*ptr=(ganttNode *)malloc(sizeof(ganttNode)); ptr->processNumber=process; ptr->start=startTime; ptr->end=endTime; ptr->link=NULL; if(head){ endNode=head; while(endNode->link)endNode=endNode->link; endNode->link=ptr; } else head=ptr; return head; }

void SRTF(int processCount,int *startTime,int *burstTime){ int i,flag,temp,end,minBurst,remainingTimeVal,minRemainingTime,process,presentTime,totalRemainingTime=0,*remainingTime=(int *)calloc(processCount,sizeof(int)); ganttNode *ptr,*head=NULL; float waitingTime=0,turnaroundTime=0,responseTime=0; for(i=1,flag=1,process=0,remainingTimeVal=burstTime[process];i if(startTime[process]==startTime[i]){ if(minBurst>burstTime[i]){ minBurst=burstTime[i]; remainingTimeVal=burstTime[i]; process=i; } remainingTime[i]=burstTime[i]; continue; } else if(remainingTimeVal>burstTime[i]){ remainingTimeVal-=(startTime[i]-startTime[i-1]); remainingTime[process]=remainingTimeVal; head=addNode(head,process,startTime[process],startTime[i]); process=i; flag=1; remainingTimeVal=burstTime[process]; } else{ remainingTimeVal-=(startTime[i]-startTime[i-1]); remainingTime[i]=remainingTime[i]?remainingTime[i]:burstTime[i]; } } remainingTime[process]=remainingTimeVal; head=addNode(head,process,startTime[process],startTime[i-1]); presentTime=startTime[processCount-1]; ptr=head; for(i=0;i while(i minRemainingTime=remainingTime[i]; process=i; for(i=0;i if(remainingTime[i] && remainingTime[i] minRemainingTime=remainingTime[i]; process=i; } } head=addNode(head,process,presentTime,presentTime+remainingTime[process]); presentTime+=remainingTime[process]; remainingTime[process]=0; for(i=0;i } for(i=0;i end=startTime[i]; for(ptr=head,flag=1;ptr;ptr=ptr->link){ if(flag && ptr->processNumber==i){ responseTime+=ptr->start-startTime[i]; flag=0; } if(ptr->processNumber==i){ waitingTime+=(ptr->start)-end; end=ptr->end; temp=ptr->end-startTime[i]; } } turnaroundTime+=temp; } turnaroundTime/=processCount; responseTime/=processCount; waitingTime/=processCount; printf(" Avg Resp.: %.2f, Avg. T.A.: %.2f, Avg. Wait: %.2f ",responseTime,turnaroundTime,waitingTime); }

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!