IDLE situation using Round Robin

153 Views Asked by At

I am having trouble with calculating the correct Average wait time and Average Turnaround time when there are no processes ready to be executed. [ IDLE ]


Example of IDLE situation:
0 3
0 5
9 8
10 6

  • The first column represents Arrival Time
  • The second column represents Burst Time


for the current n process

The average wait time should be: 3.5
The average turnaround time should be: 9

But the results I get are:
The average wait time: 5
The average turnaround time: 10

Any suggestions of what I should do to fix this problem, based on my code? I know where the IDLE situation outlies and it's noted in my code. Any help would be greatly appreciated..

Where IDLE is commented, I was planning on subtracting the (save) variable from the wait_time. Since the arrival and burst time from ( before the IDLE situation occured) already completed.

#include <stdio.h>
int main()
{
   int i, total = 0, x, limit, counter = 0, t_quantum;
   int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10];

   float average_wait_time, average_turnaround_time;

   printf("\nEnter Total Number of Processes: ");
   scanf("%d", &limit);
   x = limit;

   for (i = 0; i < limit; i++)
   {
      printf("\nProvide the details for Process[%d]\n", i + 1);
      printf("Arrival Time:\t");
      scanf("%d", &arrival_time[i]);
      printf("Burst Time:\t");
      scanf("%d", &burst_time[i]);
      temp[i] = burst_time[i];
   }

   printf("\nEnter Time Quantum:\t");
   scanf("%d", &t_quantum);
        int save = 0;
   printf("\nProcess ID\t\tBurst Time\t Turnaround Time\t Waiting Time\n");
   for (total = 0, i = 0; x != 0;)
   {
      if (temp[i] <= t_quantum && temp[i] > 0)
      {
         total = total + temp[i];
         temp[i] = 0;
         counter = 1;
      }
      else if (temp[i] > 0)
      {
         temp[i] = temp[i] - t_quantum;
         total = total + t_quantum;
      }

      if (temp[i] == 0 && counter == 1)
      {
         x--;
         printf("\nProcess[%d]\t\t%d\t\t %d\t\t\t %d", i + 1, burst_time[i], total - arrival_time[i], total - arrival_time[i] - burst_time[i]);

        // printf("Completion TIme: %d\n", total);
         wait_time = wait_time + total - arrival_time[i] - burst_time[i];
         save = total - arrival_time[i] - burst_time[i];
         turnaround_time = turnaround_time + total - arrival_time[i];
        // printf("CT: %d\n", turnaround_time);
         counter = 0;
      }

      if (i == limit - 1)
      {
         i = 0;
      }
      else if (arrival_time[i + 1] <= total)
      {
         i++;
      }
      else
      {
         // IDLE when temp[i] == 0
        // limit +=1;
         i++;
        
      }
   }

   average_wait_time = wait_time *1.0 / limit;
   average_turnaround_time = turnaround_time *1.0 / limit;
 

   printf("\n\nAverage Waiting Time:\t%f", average_wait_time);
   printf("\nAvg Turnaround Time:\t%f\n", average_turnaround_time);

   return 0;
}
0

There are 0 best solutions below