Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago