Question: #include #include #include #define MAXNUMBER 1 0 0 typedef struct { char id [ 1 0 ] ; int arrival _ time; int burst _

#include
#include
#include
#define MAXNUMBER 100
typedef struct {
char id[10];
int arrival_time;
int burst_time;
int wait_time;
int turnaround_time;
} Process;
Process allprocess[MAXNUMBER];
//it will collect all data from file and find how many time cost.
int read_processes(const char *filename){
//by helpful hints
int i =0;
int allticks =0;
FILE *file = fopen(filename,"r");
if (file == NULL){
printf("Unable to open file
");
exit(EXIT_FAILURE);
}
while(fscanf(file,"%[^,],%d",allprocess[i].id,&allprocess[i].burst_time)==2){
allprocess[i].arrival_time = i;
allprocess[i].wait_time =0;
allprocess[i].turnaround_time =0;
allticks += allprocess[i].burst_time;
i++;
}
fclose(file);
return allticks;
}
void fcfs(int num_processes){
int P =0;
Process working[MAXNUMBER];
printf("First Come First Served
");
for(int i =0; i < num_processes; i++){
if(i == allprocess[i].arrival_time){
working[i]= allprocess[i];
}
printf("T%d : P%d - Burst left %d, Wait time %d, Turnaround time %d
",i,working[P].arrival_time,working[P].burst_time,working[P].wait_time,working[P].turnaround_time);
if(P < i){
if(i < number_process){
for(int tmp = P;(i-tmp)!=0;tmp++){
working[tmp+1].wait_time++;
}
}else{
for(int tmp = P;(number_process - tmp)!=0;tmp++){
working[tmp+1].wait_time++;
}
}
}
if(working[P].burst_time !=0){
working[P].burst_time--;
working[P].turnaround_time++;
}else{
P++;
}
}
}
void sjf(int num_processes){
// Your SJF implementation goes here
}
void round_robin(int num_processes, int quantum){
// Your Round Robin implementation goes here
}
int main(int argc, char *argv[]){
if (argc <3|| argc >4){
printf("Wrong format, please use correct format
");
return EXIT_FAILURE;
}
int num_processes = read_processes(argv[argc -1]);
if (strcmp(argv[1],"-f")==0){
fcfs(num_processes);
} else if (strcmp(argv[1],"-s")==0){
sjf(num_processes);
} else if (strcmp(argv[1],"-r")==0){
if (argc !=4){
printf("For Round Robin, provide a time quantum.
");
return EXIT_FAILURE;
}
int quantum = atoi(argv[2]);
if (quantum <=0){
printf("Time quantum must be a positive integer.
");
return EXIT_FAILURE;
}
round_robin(num_processes, quantum);
} else {
printf("Invalid algorithm option.
");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
why it has core dumped

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 Programming Questions!