csenotes12

Desgin with multilevel queue

Apr 9th, 2019
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.63 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.       int i, limit, total = 0, x, counter = 0, time_quantum,j;
  6.      
  7.       int wait_time = 0, turnaround_time = 0,pos,z,p[10],prio[10], a_time[10], b_time[10], temp[10],b;
  8.      
  9.       float average_wait_time, average_turnaround_time;
  10.      
  11.       printf("\nEnter Total Number of Processes:");
  12.      
  13.       scanf("%d", &limit);
  14.      
  15.       x = limit;
  16.       for(i = 0; i < limit; i++)
  17.       {
  18.         p[i]=i+1;
  19.        
  20.         prio[i]=0;
  21.             printf("\nEnter total Details of Process[%d]\n", i + 1);
  22.             printf("Arrival Time:\t");
  23.             scanf("%d", &a_time[i]);
  24.             printf("Burst Time:\t");
  25.             scanf("%d", &b_time[i]);
  26.             temp[i] = b_time[i];
  27.       }
  28.        
  29.       printf("\nEnter the Time Quantum:");
  30.       scanf("%d", &time_quantum);
  31.       printf("\nProcess ID\t\tBurst Time\t Turnaround Time\t Waiting Time\t Priority\n");
  32.       for(total = 0, i = 0; x != 0;)
  33.       {
  34.  
  35.             for(z=0;z<limit;z++)
  36.             {
  37.             int temp1;
  38.             pos=z;
  39.             for(j=z+1;j<limit;j++)
  40.             {
  41.                 if(prio[j]<prio[pos])
  42.                 pos=j;
  43.             }
  44.          
  45.         temp1=prio[z];
  46.    
  47.         prio[z]=prio[pos];
  48.    
  49.         prio[pos]=temp1;
  50.          
  51.             temp1=b_time[z];
  52.             b_time[z]=b_time[pos];
  53.             b_time[pos]=temp1;
  54.                     temp1=a_time[z];
  55.                 a_time[z]=a_time[pos];
  56.             a_time[pos]=temp1;
  57.  
  58.             temp1=p[z];
  59.                 p[z]=p[pos];
  60.             p[pos]=temp1;
  61.  
  62.             temp1=temp[z];
  63.                 temp[z]=temp[pos];
  64.             temp[pos]=temp1;
  65.             }
  66.         {
  67.         }
  68.            
  69.             if(temp[i] <= time_quantum && temp[i] > 0)
  70.             {
  71.                   total = total + temp[i];
  72.                   temp[i] = 0;
  73.                   counter = 1;
  74.             }
  75.            
  76.             else if(temp[i] > 0)
  77.             {
  78.                   temp[i] = temp[i] - time_quantum;
  79.                   total = total + time_quantum;
  80.             }
  81.  
  82.     for(b=0;b<limit;b++)
  83.         {
  84.             if(b==i)
  85.             prio[b]+=1;
  86.             else
  87.             prio[b]+=2;
  88.         }
  89.  
  90.             if(temp[i] == 0 && counter == 1)
  91.             {
  92.                   x--;
  93.                   printf("\nProcess[%d]\t\t%d\t\t %d\t\t %d\t\t%d", p[i], b_time[i], total - a_time[i], total - a_time[i] - b_time[i],prio[i]);
  94.                   wait_time = wait_time + total - a_time[i] - b_time[i];
  95.                   turnaround_time = turnaround_time + total - a_time[i];
  96.                   counter = 0;
  97.             }
  98.             if(i == limit - 1)
  99.             {
  100.                   i = 0;
  101.            
  102.             }
  103.             else if(a_time[i + 1] <= total)
  104.             {
  105.                   i++;
  106.            
  107.             }
  108.             else
  109.             {
  110.                   i = 0;
  111.            
  112.             }      
  113.       }
  114.       return 0;
  115. }
Add Comment
Please, Sign In to add comment