Implement FCFS and SJF scheduling algorithms in C

Programming Style Guidelines:

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

The major purpose of programming style guidelines is to make programs easy to read and understand. Good programming style helps make it possible for a person knowledgeable in the application area to quickly read a program and understand how it works.1. Your program should begin with a comment that briefly summarizes what it does. For this course, this comment should also include your Name and pantherID.2. Use additional comments when needed in order for a reader to understand what is happening (see also, point 3).3. Variable names and function names should be sufficiently descriptive so that a knowledgeable reader can easily understand what the variable means and what the function does. If this is not possible, comments should be added to make the meaning clear.4. Use consistent indentation to emphasize block structure.5. Use names of moderate length for variables. Most names should be between 2 and 12 letters long.6. Use either underscores or capitalization (camelNaming) for compound names for variables. e.g: tot_vol, total_volumn, or totalVolumn. 

Objective

Implement FCFS and SJF scheduling algorithms in C and calculate the average waiting time and average turnaround time of concurrent processes.

Description:

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Input:  the number of processes along with the burst time and arrival time for each process. In addition to the desired scheduling algorithm (FCFS or SJF). The program should expect a file name and a scheduling algorithm as arguments.

Ex: myprogram myfile.txt FCFS

The file should contain the number of processes in the first line. Then, each following line should contain the burst time and arrival time of one process as follows:

“`

“`

You can find an example of the input file

here

and the code for reading the content of the file here

Note that this example is NOT the test case for grading.

the program should calculate the waiting time and turnaround time for each process if the selected scheduling algorithm was used and output the average waiting time and average turnaround time.

Output: order of execution of the processes (ex: P1 -> P3 -> P6) and the average waiting time and average turnaround time.

Sample Output:

Order of Execution: P1 -> P2 -> P3Average Waiting Time: 2.33Average Turnaround Time: 8.33 5
0 5
1 4
3 2
4 3
5 2#include
#include
int main(int argc, char **argv)
{
FILE *file;
int num_process;
int *arrival;
int *burst;
// Open the file
file = fopen(argv[1], “r”);
// Read the first line – number of processes, note the ‘&’ operator before num_process
fscanf(file, “%d”, &num_process);
// Allocate the arrays to store the arrival time and burst time, one element for each process
arrival = (int *)malloc(num_process * sizeof(int));
burst = (int *)malloc(num_process * sizeof(int));
// Read each line of the file for arrival time and burst time, note that no ‘&’ operator used here
for (int i = 0; i < num_process; i++) { fscanf(file, "%d", arrival + i); fscanf(file, "%d", burst + i); } // You should close the file after reading, even though it's usually ok to forget fclose(file); // In this example I only print the values, in your assignment you have to compute the execution sequence // as well as the average waiting time and average turnaround time printf("There are %d processes\n", num_process); for (int i = 0; i < num_process; i++) { printf("Process %d arrives at %d with burst time %d\n", i + 1, arrival[i], burst[i]); } // And remember to release the dynamically allocated memory after using free(arrival); free(burst); return 0; }

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER