简体   繁体   English

操作系统中的循环调度算法

[英]Round-Robin Scheduling Algorithm in OS

I have been trying to understand how the round robin concept and how the algorithm works.我一直在试图了解循环的概念以及算法的工作原理。 I have tried running this code in ubuntu, and i'm unable to get the answer that i wanted.我曾尝试在 ubuntu 中运行此代码,但无法得到我想要的答案。

So based on the Round Robin Scheduling Algorithm;所以基于循环调度算法; Let's say there are 3 processes.假设有 3 个进程。 Where Processor 1 - Burst Time is 24, Processor 2 - Burst time is 3 and Processor 3 - Burst time is 3. and the Time Quantum is 3.其中处理器 1 - 突发时间为 24,处理器 2 - 突发时间为 3,处理器 3 - 突发时间为 3。时间量子为 3。

Based on this information, the waiting time for P1 is 6, P2 is 4 and P3 is 7. So the Turn Around Time is P1 is 30, P2 is 7 and P3 is 10.根据此信息,P1 的等待时间为 6,P2 为 4,P3 为 7。因此,周转时间为 P1 为 30,P2 为 7,P3 为 10。

Average Turn Around time is 15.6667 and The average waiting time is 5.667平均周转时间为 15.6667 平均等待时间为 5.667

Based on the code below, if i run it, it would return me;根据下面的代码,如果我运行它,它会返回给我; for waiting time - P1 is 6, P2 is 3 and P3 is 6, Turn around time P1 is 30, P2 is 6, P3 is 9.等待时间 - P1 为 6,P2 为 3,P3 为 6,周转时间 P1 为 30,P2 为 6,P3 为 9。

And the Average Turn Around time is 15.0000 and The average waiting time is 5.000平均周转时间为 15.0000 平均等待时间为 5.000

I'm unable to figure out the error.我无法弄清楚错误。 Can any one help me with this problem and provide an explanation to error and solution?任何人都可以帮助我解决这个问题并提供错误和解决方案的解释吗?

#include<stdio.h>
#include<curses.h>
int main()
{
   int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
   float awt=0,att=0,temp=0;
   clear();
   printf("Enter the no of processes -- ");
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
       printf("\nEnter Burst Time for process %d -- ", i+1);
       scanf("%d",&bu[i]);
       ct[i]=bu[i];
   }
   printf("\nEnter the size of time slice -- ");
   scanf("%d",&t);
   max=bu[0];
   for(i=1;i<n;i++)
       if(max<bu[i])
           max=bu[i];
   for(j=0;j<(max/t)+1;j++)
       for(i=0;i<n;i++)
           if(bu[i]!=0)
             if(bu[i]<=t)
             {
                tat[i]=temp+bu[i];
                temp=temp+bu[i];
                bu[i]=0;
             }
             else
             {
                bu[i]=bu[i]-t;
                temp=temp+t;
             }
   for(i=0;i<n;i++)
   {
      wa[i]=tat[i]-ct[i];
      att+=tat[i];
      awt+=wa[i];
   }
   printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUND TIME\n");
   for(i=0;i<n;i++)
   {
       printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wa[i],tat[i]);
   }
   printf("\nThe Average Turnaround time is -- %f",att/n);
   printf("\nThe Average Waiting time is -- %f ",awt/n);
   getch();
}

The code is returning the right answer.代码返回正确答案。

All the processes arrived at time 0.所有进程都在时间 0 到达。

P1 - 0-3 21 units remaining P1 - 0-3剩余 21 个单位

P2 - 3-6 0 units remaining P2 - 3-6剩余 0 个单位

P3 - 6-9 0 units remaining P3 - 6-9剩余 0 个单位

P1 - 9-30 0 units remaining P1 - 9-30 0 个剩余单位

P1 waited 6 units, P2 waited 3 units and P3 waited 6 units. P1 等了 6 个单位,P2 等了 3 个单位,P3 等了 6 个单位。

Note that Waiting time is the amount of time a process is waiting without being executed after given to the scheduler.请注意,等待时间是进程在提供给调度程序后等待而未执行的时间。 Turnaround time is the total time a process took to complete its execution (Waiting time + Burst time).周转时间是进程完成执行所需的总时间(等待时间 + 突发时间)。

Avg waiting time: (6+3+6) / 3 = 15平均等待时间:(6+3+6) / 3 = 15

Average Turnaround time = (30+6+9) / 3 = 15平均周转时间 = (30+6+9) / 3 = 15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM