Preemptive Round Robin C program

Asked By 0 points N/A Posted on -
qa-featured

Hi, anyone can give me a C program for preemptive round robin with Gantt chart.

Please help me.

SHARE
Answered By 0 points N/A #163186

Preemptive Round Robin C program

qa-featured

Hello Janine,

Once such program can be implemented using the following code:

#include<stdio.h>

int ttime,i,j,temp;

main()

{

        int pname[10],btime[10],pname2[10],btime2[10];

        int n,x,z;

        printf("Enter the no. of process:");

        scanf("%d",&n);

        printf("Enter the process name and burst time for the processn");

        for(i=0;i<n;i++)

        {     

    printf("Enter the process name:");

                scanf("%d",&pname2[i]);

                printf("Enter burst time for the process %d:",pname2[i]);

                scanf("%d",&btime2[i]);

        }

        printf("PROCESS NAME tt BURST TIMEn");

        for(i=0;i<n;i++)

            printf("%dttt %dn",pname2[i],btime2[i]);

            z=1;

        while(z==1)

        {

ttime=0;

        for(i=0;i<n;i++)

        { 

pname[i]=pname2[i];

            btime[i]=btime2[i];

        }

 

            printf ("PRESS 1.ROUND ROBIN 2.EXITn");

            scanf("%d",&x);

        switch(x)

        {

        case 1:

                rrobin(pname,btime,n);

                break;

        case 2:

                exit(0);

                break;

        default:

                printf("Invalid option");

               break;

       }

       printf("nn If you want to continue press 1:");

       scanf("%d",&z);

       }

}

     

 rrobin(int pname[],int btime[],int n)

       {

            int tslice;

            j=0;

            printf("nt ROUND ROBIN SCHEDULING nn");

            printf("Enter the time slice:n");

            scanf("%d",&tslice);

            printf("PROCESS NAME t REMAINING TIMEt TOTAL TIME");

    

 

while(j<n)

            { 

      for(i=0;i<n;i++)

{

      if(btime[i]>0)

                        { 

if(btime[i]>=tslice)

                                    { 

ttime+=tslice;

                                                btime[i]=btime[i]-tslice;

                                                printf("n%dtt %d tt %d",pname[i],btime[i],ttime);

                                                if(btime[i]==0)

                                                 j++;

                                    }

                                    else

                                    { 

ttime+=btime[i];

                                                btime[i]=0;

                                                printf("n%dtt %d tt %d",pname[i],btime[i],ttime);

                                    }

}

 }

       }

}

 

If you want to check its output just go here: http://meansofmine.blogspot.com/2011/04/c-program-to-implement-round-robin.html

Regards,

Nicke

 

Related Questions