Showing posts with label for. Show all posts
Showing posts with label for. Show all posts

Wednesday, April 2, 2014

C code for Round Robin Scheduling

Round Robin: 
A straightforward way to reduce the penalty that short jobs suffer with FCFS is to use preemption based on a clock. The simplest such policy is round robin. A clock interrupt is generated at periodic intervals. When the interrupt occurs, the currently running process is placed in the ready queue, and the next ready job is selected on a FCFS basis. This technique is also known as time slicing, because each process is given a slice of time before being preempted.

/* C program to implement Round Robin Scheduling */

#include <stdio.h>
#include <conio.h>

int initialise();
void sort();
void print();
void GC();
void WT(int,int,char);
int RR();
float averagewaitingtime();
float averageturnaroundtime();

int p[15],a[15],b[15],br[15],gc[30],n,time,k;
static int wt[15];
void main()
  {
    int k;
    clrscr();
    printf("Enter the time slice:");
     fflush(stdin);
    scanf("%d",&time);
     n=initialise();
     sort();
     k=RR();
     print();
     printf("

Average Wating time = %.2fmsec. & Average Turnaround time= %.2fmsec.

",averagewaitingtime()/n,averageturnaroundtime()/n);
     GC(k);
     getch();
  }

int RR()
  {
   int i,flag,left,k=0;
    do
      {
    flag=1;
    for(i=0;i<n;i++)
     {
       if ( br[i]==0  || (a[i] > (k*time)))
         continue;
       if(br[i] <= time)
        {
          left=br[i];
          gc[k++]=p[i];
          br[i]=0;
          WT(i,left,l);
        }
       else
        {
          gc[k++]=p[i];
          br[i]-=time;
          WT(i,time,g);
        }
     }
      for(i=0;i<n;i++)
    if(br[i]!=0)
      flag=0;
      }while(!flag);
   return k;
  }


 void WT(int i,int add,char ch)
  {
    int j;
    if ( ch == l )
     {
       for(j=0;j<n;j++)
       if( j!=i && br[j]!=0 )
          wt[j]+=add;
     }
    if ( ch == g )
     {
       for(j=0;j<n;j++)
    if ( j!=i && br[j]!=0 )
     wt[j]+=add;
     }
  }



 void print()
    {
      int i;
       printf("

    | Process | Arrival time | Burst_Time | Waiting_Time | T_arnd_Time |
");
       printf("    -------------------------------------------------------------------
");
    for(i=0;i<n;i++)
     printf("    |%4d     |%8d      |%6d      |%8d      |%6d       |

",p[i],a[i],b[i],wt[i],b[i]+wt[i]);
       printf("    --------------------------------------------------------------------
");
    }

  void GC(int g)
   {
     int i;
     printf("


AND THE G.C IS :::

");
      for(i=0;i<g;i++)
       printf("------");
      printf("
");
       for(i=0;i<g;i++)
          {
    printf("|  %d  ",gc[i]);
     if(i==g-1)
      printf("|");
    }
     printf("
");
     for(i=0;i<g;i++)
      printf("------");
      printf("
");
   }

void sort()
 {
   int i,n,t,j;
   for(i=0;i<n;i++)
    {
    for(j=i+1;j<n;j++)
     {
      if(a[i] > a[j])
       {
     t=p[i];
     p[i]=p[j];
     p[j]=t;

     t=a[i];
     a[i]=a[j];
     a[j]=t;

     t=b[i];
     b[i]=b[j];
     b[j]=t;

     t=br[i];
     br[i]=br[j];
     br[j]=t;
       }
    }
  }
}

 int initialise()
  {
    FILE *fp;
    int i=0,n1,n2,n3;
    fp=fopen("sjf.txt","r");
    while(fscanf(fp,"%d%d%d",&n1,&n2,&n3)!=EOF)
      {
     p[i]=n1;
     a[i]=n2;
     br[i]=b[i++]=n3;
      }
    fclose(fp);
    return i;
  }
 float averagewaitingtime()
  {
    float sum=0;
    int i;
     for(i=0;i<n;i++)
    sum+=wt[i];
      return sum;
  }

  float averageturnaroundtime()
  {
    float sum=0;
    int i;
     for(i=0;i<n;i++)
    sum+=(wt[i]+b[i]);
      return sum;
  }


Input File:

1 0 3
2 1 3
3 2 2

//Output Of the above program:-

C code for Round Robin Scheduling

C code for Round Robin Scheduling


Read More..

Sunday, March 9, 2014

‘Fantasy’ for Camera360 apk Download

‘Fantasy’ for Camera360 apk
‘Fantasy’ for Camera360 apk

Current Version : 3.2
Requires Android : 1.6 and up
Category : Photography
Size : 3.2M






‘Fantasy’ for Camera360 apk Description

Working with Belgium Artist Ben Heine, Camera360 develops 10 wonderful templates which are part of Ben Heine’s ‘Pencil Vs Camera’ works. It will bring you something beyond your imagination.‘Fantasy’ Templates Package brings much surprise to phone photography. Photography is not just a kind of recording; with ‘Fantasy’ you can make your own wonder world by joining reality with fantasies.

*Only work with Camera360
*After installing the Fantasy Templates Package , you can find 10 templates in the ‘scenes’of Camera360.


‘Fantasy’ for Camera360 apk Videos and Images





Read More..