Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Round Robin Process Scheduling

Round Robin Process Scheduling

Ratings: (0)|Views: 1,192|Likes:
Published by Sharanangadi
c program to implement Round Robin algorithm
c program to implement Round Robin algorithm

More info:

Published by: Sharanangadi on Jul 28, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





/* Information Science & Engineering *//* BEC Bagalkot , (Karnataka) INDIA. *//*angadi.sharan@yahoo.in*/
Write a C/C++ program to compute average waiting time and average turnaroundtime for Round robin scheduling algorithm. The program should accept arrivaltime and burst time as input. Assume suitable time quantum as input.
$vim 5.c#include<stdio.h>typedef struct proc{ int at,bt,status,t_bt;int proc,est;}P;typedef struct et{ int st,et,p;}ET;P p[15];ET ti[40];int z;//to maintain time countint check(int n){ int i;for(i=0;i<n;i++){ if(p[i].status==0)return 1;}return 0;}void cal_proc(int n,int qtm) //qtm is Quantum Time{ int ct=0,i,j,pros;while(check(n)){for(i=0;i<n;i++){if(p[i].status==0 && p[i].at<=ct){ if(p[i].bt>qtm){ p[i].bt-=qtm;ti[z].st=ct;
ti[z].et=ct+qtm;ti[z].p=i;z++;ct+=qtm;}else{p[i].status=1;ti[z].st=ct;ti[z].et=ct+p[i].bt;ct+=p[i].bt;ti[z].p=i;z++;}//ELSE}//if }//for }//while}//FUNCTIONvoid print_awt_atat(int n){ int i,j,flag,tat[15],wt[15];float temp=0,atat=0,awt=0;for(j=0;j<n;j++){ flag=1;for(i=0;i<z;i++){if(ti[i].p==j){ if(flag)wt[j]=ti[i].st,flag=0;temp=0;while(ti[i+1].p!=j && i+1<z){ temp+=(ti[i+1].et-ti[i+1].st);i++;}if(i+1<z)wt[j]+=temp;}}wt[j]-=p[j].at;tat[j]=wt[j]+p[j].t_bt;}for(i=0;i<n;i++){awt+=wt[i];atat+=tat[i];
}awt/=n*1.0;atat/=n*1.0;  printf("\n\tProc A_T B_T W_T TA_T\t");printf("\n\t______________________________________\n\n");for(i=0;i<n;i++)printf("\t%d\t%d\t%d\t%d\t%d\n",p[i].proc,p[i].at,p[i].t_bt,wt[i],tat[i]);printf("\n\t_______________________________________\n");printf("\n\n\t\tAverage Waiting time = %f\n",awt);printf("\n\n\t\tAverage Turn around time = %f\n",atat);}int main(){ int n,i,qntm;printf("\n\n\t\tEnter the no of Process (max 15) : ");scanf("%d",&n);printf("\n\n\t\tEnter the arrivel time of process \n");for(i=0;i<n;i++){ printf("\t\tprocess P%d : ",i);scanf("%d",&p[i].at);}printf("\n\n\t\tEnter the Burst time of process \n");for(i=0;i<n;i++){ printf("\t\tprocess P%d : ",i);scanf("%d",&p[i].bt);p[i].status=0;p[i].proc=i;p[i].t_bt=p[i].bt;}printf("\n\n\t\tEnter the Quantum Time : ");scanf("%d",&qntm);cal_proc(n,qntm);print_awt_atat(n); return 0;}/*===========================Out_put=================================*/
$cc 5.c$./a.out
Enter the no of Process (max 15) : 4

Activity (7)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
kamakshi2 liked this
Sonal Srivastava liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->