Question: PROCESS * sjf _ process _ selector ( PROCESS _ LIST * pl ) { / / Don't change the first line of the existing

PROCESS* sjf_process_selector(PROCESS_LIST* pl){
// Don't change the first line of the existing code
PROCESS* p;
// Initialize the shortest process pointer to NULL
PROCESS* shortest_process = NULL;
// Iterate through the process list to find the process with the shortest remaining time
for (int i =0; i < pl->num_processes; i++){
PROCESS* current_process = pl->processes[i];
// If the current process is shorter than the previously found shortest process
// or if there's no shortest process found yet, update the shortest process pointer
if (shortest_process == NULL || current_process->time_remaining < shortest_process->time_remaining){
shortest_process = current_process;
}
}
// Assign the shortest_process to p
p = shortest_process;
// Return the process with the shortest remaining time
return p;
}
"FAILED": [
"test_2proc_0entry_1entry_sjf",
"5proc_sjf"
]
These Test cases are failing for this code.
Test(SJF,5proc_sjf,.disabled=false){
SCHEDULER_STATS* stats = get_empty_stats_block();
SCHEDULER_PARAMS params =(SCHEDULER_PARAMS){
.time_slice =1,
.process_selection_func = sjf_process_selector
};
test_5proc(params, stats);
cr_expect(stats->num_processes_started==5);
cr_expect(stats->num_processes_completed==5);
cr_expect(stats->completion_time==30.0f);
cr_expect(stats->sum_of_turnaround_times==65.0f);
cr_expect(stats->sum_of_response_time==29.0f);
cr_expect(stats->average_turnaround_time ==13.0f);
cr_expect(stats->average_response_time==5.80f);
printf("-----------------------------------
");
}
Test(RR, test_2proc_0entry_0entry_rr,.disabled=false){
SCHEDULER_STATS* stats = get_empty_stats_block();
SCHEDULER_PARAMS params =(SCHEDULER_PARAMS){
.time_slice =1,
.process_selection_func = rr_process_selector
};
test_2proc_0entry_0entry(params, stats);
cr_expect(stats->num_processes_started==2);
cr_expect(stats->num_processes_completed==2);
cr_expect(stats->completion_time==10);
cr_expect(stats->sum_of_turnaround_times==19);
cr_expect(stats->sum_of_response_time==1);
cr_expect(stats->average_turnaround_time ==9.5);
cr_expect(stats->average_response_time==0.5);
printf("-----------------------------------
");
}
Make the changes in the code so the test case passes.

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!