Monday, 22 April 2013

C program for Round Robin Scheduling Policy


#include<stdio.h>
#include<conio.h>
#define MAX 5
void main (){
                clrscr();
                int pname[MAX],brtime[MAX];
                int end[MAX+1],start[MAX];
                int qtm,total=0,rem =0;
                int num = 0, i;
                for(i=0;i<MAX;i++){
                                brtime[i] = 0;
                }
                printf("\t\tRound-Robin SCHEDULING");
                printf("\nEnter the number of processes  (max. 5): ");
                scanf("%d",&num);
                printf("\nEnter the quantum size: ");
                scanf("%d",&qtm);
                for(i=0;i<num;i++){
                                printf("\nEnter process name, burst time: ");
                                scanf("%d %d",&pname[i],&brtime[i]);
                                total= total + brtime[i];
                }
                rem = total;
                printf("\n");
                while(rem!=0){
                                for(i=0;i<num;i++){
                                                if(brtime[i]==0){
                                                                //do nothing
                                                }
                                                else if(brtime[i]>=qtm){
                                                                brtime[i] = brtime[i] - qtm;
                                                                printf("\n%d ->%d",pname[i],qtm);
                                                                rem = rem- qtm;
                                                }

                                                else{
                                                                printf("\n%d ->%d",pname[i],brtime[i]);
                                                                rem= rem - brtime[i];
                                                                brtime[i]=0;
                                                }

                                }
                }
                printf("\n\nTotal Time = %d",total);
                getch();
 }

Sample Output:

                       Round-Robin SCHEDULING
Enter the number of processes (max. 5): 3
Enter the quantum size: 3
Enter process name, burst time: 1     6
Enter process name, burst time: 2     2
Enter process name, burst time: 3     7

1 ->3
2 ->2
3 ->3
1 ->3
3 ->3
3 ->1

Total Time = 15_

©Dixit Bhatta 2013

No comments:

Post a Comment

Was this post helpful? Ask any questions you have, I will try to answer them for you.