Sign in or 

|
intel_ram2002 |
ROUND ROBIN SCHEDULING
Oct 30 2006, 8:26 PM EST
ROUND ROBIN SCHEDULING
#include<stdio.h> int main() { int i,j,k,tbt=0,nop=0,ts=0,flag[20],rem[20],occ[20],to,from=0, wt[20],tt[20],b[20]; float twt=0,ttt=0; float awt,att; printf("\n Enter the no. of processes: "); scanf("%d", &nop); printf("\n Enter the time slice: "); scanf("%d", &ts); for(i=0;i<nop;i++) { rem[i]=b[i]=wt[i]=tt[i]=occ[i]=0; printf("\n Enter burst time for process %d: ", i+1); scanf("%d", &b[i]); rem[i]=b[i]; tbt+=b[i]; flag[i]=0; } k=0; from=0; i=0; printf("\n TIME \tPROCESS ID"); while(k<tbt) { if(!flag[i]) { if(rem[i]<ts) to=from+rem[i]; else to=from+ts; printf("\n%d - %d\t%d", from, to, i+1); rem[i]=rem[i]-(to-from); if((rem[i]==0)&&(flag[i]==0)) { flag[i]=1; wt[i]=from-occ[i]; tt[i]=to; } occ[i]=occ[i]+(to-from); k=k+(to-from); from=to; } i++; if(i==nop) i=0; } twt=ttt=0; for(k=0;k<nop;k++) { twt=twt+(float)wt[k]; ttt=ttt+(float)tt[k]; } awt=twt/nop; att=ttt/nop; printf("\n PROCESS ID \t WAIT TIME \t TURN AROUND TIME "); for(i=0;i<nop;i++) printf("\n%d\t%d\t%d", i+1,wt[i],tt[i]); printf("\n total wait time: %f", twt); printf("\n total turn around time: %f", ttt); printf("\n average wait time: %f", awt); printf("\n average turn around time: %f", att); } 2 out of 2 found this valuable. Do you? |