0

can someone pleae tell me what's wrong in these two functions? They are supposed to perfrom the round robin scheduling.

void generate_processes(Process processes[], int num_processes) { for (int i = 0; i < num_processes; i++) { processes[i].pid = i + 1; processes[i].arrival_time = rand() % 10; processes[i].burst_time = (rand() % 10) + 1; processes[i].remaining_time = processes[i].burst_time; processes[i].waiting_time = 0; processes[i].turnaround_time = 0; } } void round_robin(Process processes[], int num_processes, int quantum) { int time = 0; int completed_processes = 0; while (completed_processes < num_processes) { for (int i = 0; i < num_processes; i++) { if (processes[i].arrival_time <= time && processes[i].remaining_time > 0) { int time_slice = (processes[i].remaining_time > quantum) ? quantum : processes[i].remaining_time; time += time_slice; processes[i].remaining_time -= time_slice; if (processes[i].remaining_time == 0) { completed_processes++; processes[i].turnaround_time = time - processes[i].arrival_time; processes[i].waiting_time = processes[i].turnaround_time - processes[i].burst_time; } } else { time++; } } } }

15th Apr 2023, 1:48 PM
ss7
1 ответ
+ 3
Can you share a private code with that? I cant run the code here
15th Apr 2023, 3:21 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar