Round Robin Scheduling Program in C++
Process scheduling is an important component for process management. In a multi-user and a time-sharing system, response time is one of the most important objective to be accomplished.
Round Robin Scheduling Algorithm
1. The queue structure in ready queue is of First In First Out (FIFO) type.
2. A fixed time is allotted to every process that arrives in the queue. This fixed time is known as time slice or time quantum.
3. The first process that arrives is selected and sent to the processor for execution. If it is not able to complete its execution within the time quantum provided, then an interrupt is generated using an automated timer.
4. The process is then stopped and is sent back at the end of the queue. However, the state is saved and context is thereby stored in memory. This helps the process to resume from the point where it was interrupted.
5. The scheduler selects another process from the ready queue and dispatches it to the processor for its execution. It is executed until the time Quantum does not exceed.
6. The same steps are repeated until all the process are finished.
The round robin algorithm is simple and the overhead in decision making is very low. It is the best scheduling algorithm for achieving better and evenly distributed response time.
Source Code:
- //ROUND ROBIN//
- #include<iostream>
- #include<conio.h>
- using namespace std;
- void SearchStack01(int pnt,int tm);
- void SearchStack02(int pnt, int tm);
- void AddQue(int pnt);
- int at[50], bt[50], ct[50]={0}, qt, rqi[50]={0}, c=0, st, flg=0, tm=0, noe=0, pnt=0, btm[50]={0}, tt, wt;
- float att, awt;
- main()
- {
- cout<<"ROUND ROBIN ALGO : INPUT 5 PROCESSES\n";
- cout<<"\n\t\tHere Some Attrib use in program \n";
- cout<<"AT = Arrival Time \nBT = Burst Time\nCT = Completion Time\nTT = Turnaround Time\nWT = Waiting Time\n\n";
- for(int x=0;x<5;x++){
- cout<<"\nProcess "<<x+1;
- cout<<"\nAT=";
- cin>>at[x];
- cout << "BT=";
- cin>>bt[x];
- btm[x]=bt[x];}
- cout<<"\nEnter time quantum:";
- cin>>qt;
- system("CLS");
- cout<<endl<<"GANTT CHART"<<endl<<at[0];
- do{
- if(flg==0){
- st=at[0];
- //---ReduceBT
- if(btm[0]<=qt){
- tm=st+btm[0];
- btm[0]=0;
- SearchStack01(pnt,tm);}
- else{
- btm[0]=btm[0]-qt;
- tm=st+qt;
- SearchStack01(pnt,tm);
- AddQue(pnt);}
- }//if
- else{
- pnt=rqi[0]-1;
- st=tm;
- //---DeleteQue
- for(int x=0;x<noe && noe!=1;x++){
- rqi[x]=rqi[x+1];}
- noe--;
- //---ReduceBT
- if(btm[pnt]<=qt){
- tm=st+btm[pnt];
- btm[pnt]=0;
- SearchStack02(pnt, tm);}
- else{
- btm[pnt]=btm[pnt]-qt;
- tm=st+qt;
- SearchStack02(pnt, tm);
- AddQue(pnt);}
- }//else
- //AssignCTvalue
- if(btm[pnt]==0){
- ct[pnt]=tm;
- }//if
- flg++;
- cout<<"]-P"<<pnt+1<<"-["<<tm;
- }while(noe!=0);
- cout<<"\n\nPROCESS\t AT\t BT\t CT\t TT\t WT\n";
- for(int x=0;x<5;x++){
- tt=ct[x]-at[x];
- wt=tt-bt[x];
- cout<<"P"<<x+1<<" \t "<<at[x]<<" \t "<<bt[x]<<" \t "<<ct[x]<<" \t "<<tt<<" \t "<<wt<<"\n";
- awt=awt+wt;
- att=att+tt;
- }//for
- cout<<"\nAVERAGE TT: "<<att/5<<"\nAVERAGE WT: "<<awt/5;
- }//main
- void SearchStack01(int pnt,int tm){
- for(int x=pnt+1;x<5;x++){
- if(at[x]<=tm){
- rqi[noe]=x+1;
- noe++;}
- }//for
- }//void
- void SearchStack02(int pnt, int tm){
- for(int x=pnt+1;x<5;x++){
- //---CheckQue
- int fl=0;
- for(int y=0;y<noe;y++){
- if(rqi[y]==x+1){
- fl++;}}
- if(at[x]<=tm && fl==0 && btm[x]!=0){
- rqi[noe]=x+1;
- noe++;}
- }//for
- }//void
- void AddQue(int pnt){
- rqi[noe]=pnt+1;
- noe++;
- }//void
What does stack 1 and stack 2 function do?
ReplyDeletestack01 and stack02 is help us to reducing burst time by FIFO method......thanks .
Delete##support us by follow us on google+ and subscribe on youtube.
what is the pnt, tm, noe, c, rqi and Btm...?
ReplyDeleteplease how can i reduce the processes in your code
ReplyDelete