Description
You will write a program (name it scheduler.c) that can take a list of processes’ burst time from a file and determine the sequence of executions for those processes using FCFS scheduling and round-robin scheduling. The scheduler will also output the average wait time and the average turnaround time.
You may assume that all processes arrive and the same time and the time slice for round-robin is 10ms.
Your program will take in two arguments. The first argument will indicate what type of scheduling algorithm the user wants to use. The second argument will be the name of the input file.
For example if the content of data.txt is
144
43
54
19
The output of your program should look like this:
hb117@uxb4:~/class/cs410/p2$ gcc -Wal -o scheduler scheduler.c
hb117@uxb4:~/class/cs410/p2$ ./scheduler 0 data.txt
P0 P1 P2 P3
Average wait time: 135.500000
Average turnaround time: 198.00000
hb117@uxb4:~/class/cs410/p2$ ./scheduler 1 data.txt
P0 P1 P2 P3 P0 P1 P2 P3 P0 P1 P2 P0 P1 P2 P0 P1 P2 P0 P2 P0 P0 P0 P0 P0 P0 P0 P0
Average wait time: 101.750000
Average turnaround time: 164.250000
Programming Assignment 2
Your program should check to see if there are exactly two arguments, and the scheduling option is valid.hb117@uxb4:~/class/cs410/p2$ ./scheduler 2 data.txt
Usage: ./schedule <option> <filename>
Available options:
0: FCFS
1: Round robin
hb117@uxb4:~/class/cs410/p2$ ./scheduler 2
Usage: ./schedule <option> <filename>
Available options:
0: FCFS
1: Round robin
To read the bursts time from the file you can use the following code example:
#include<stdio.h>
int main(int argc, char *argv[])
{
FILE *input = fopen("data.txt","r");
int burst_time;
while(fscanf(input,"%d",&burst_time)!=EOF){
printf("%dn",burst_time);
}
return 0;
}
You will need to create a struct to act like a process control block that look like this:
struct task {
int pid;
int burst;
struct task *next;
}
0 comments