Skip to main content

Round Robin Scheduling Program in C++ || dot clu

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:
  1. //ROUND ROBIN//
  2. #include<iostream>
  3. #include<conio.h>
  4. using namespace std;

  5. void SearchStack01(int pnt,int tm);
  6. void SearchStack02(int pnt, int tm);
  7. void AddQue(int pnt);
  8. 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;
  9. float att, awt;

  10. main()
  11. {
  12. cout<<"ROUND ROBIN ALGO : INPUT 5 PROCESSES\n";
  13. cout<<"\n\t\tHere Some Attrib use in program \n";
  14. cout<<"AT = Arrival Time \nBT = Burst Time\nCT = Completion Time\nTT = Turnaround Time\nWT = Waiting Time\n\n";
  15. for(int x=0;x<5;x++){
  16. cout<<"\nProcess "<<x+1;
  17. cout<<"\nAT=";
  18. cin>>at[x];
  19. cout << "BT=";
  20. cin>>bt[x];
  21. btm[x]=bt[x];}
  22. cout<<"\nEnter time quantum:";
  23. cin>>qt;
  24. system("CLS");
  25. cout<<endl<<"GANTT CHART"<<endl<<at[0];
  26. do{
  27. if(flg==0){
  28. st=at[0];
  29. //---ReduceBT
  30. if(btm[0]<=qt){
  31. tm=st+btm[0];
  32. btm[0]=0;
  33. SearchStack01(pnt,tm);}
  34. else{
  35. btm[0]=btm[0]-qt;
  36. tm=st+qt;
  37. SearchStack01(pnt,tm);
  38. AddQue(pnt);}
  39. }//if
  40. else{
  41. pnt=rqi[0]-1;
  42. st=tm;
  43. //---DeleteQue
  44. for(int x=0;x<noe && noe!=1;x++){
  45. rqi[x]=rqi[x+1];}
  46. noe--;
  47. //---ReduceBT
  48. if(btm[pnt]<=qt){
  49. tm=st+btm[pnt];
  50. btm[pnt]=0;
  51. SearchStack02(pnt, tm);}
  52. else{
  53. btm[pnt]=btm[pnt]-qt;
  54. tm=st+qt;
  55. SearchStack02(pnt, tm);
  56. AddQue(pnt);}
  57. }//else
  58. //AssignCTvalue
  59. if(btm[pnt]==0){
  60. ct[pnt]=tm;
  61. }//if
  62. flg++;
  63. cout<<"]-P"<<pnt+1<<"-["<<tm;
  64. }while(noe!=0);
  65. cout<<"\n\nPROCESS\t AT\t BT\t CT\t TT\t WT\n";
  66. for(int x=0;x<5;x++){
  67. tt=ct[x]-at[x];
  68. wt=tt-bt[x];
  69. cout<<"P"<<x+1<<" \t "<<at[x]<<" \t "<<bt[x]<<" \t "<<ct[x]<<" \t "<<tt<<" \t "<<wt<<"\n";
  70. awt=awt+wt;
  71. att=att+tt;
  72. }//for
  73. cout<<"\nAVERAGE TT: "<<att/5<<"\nAVERAGE WT: "<<awt/5;
  74. }//main
  75. void SearchStack01(int pnt,int tm){
  76. for(int x=pnt+1;x<5;x++){
  77. if(at[x]<=tm){
  78. rqi[noe]=x+1;
  79. noe++;}
  80. }//for
  81. }//void
  82. void SearchStack02(int pnt, int tm){
  83. for(int x=pnt+1;x<5;x++){
  84. //---CheckQue
  85. int fl=0;
  86. for(int y=0;y<noe;y++){
  87. if(rqi[y]==x+1){
  88. fl++;}}
  89. if(at[x]<=tm && fl==0 && btm[x]!=0){
  90. rqi[noe]=x+1;
  91. noe++;}
  92. }//for
  93. }//void
  94. void AddQue(int pnt){
  95. rqi[noe]=pnt+1;
  96. noe++;
  97. }//void


Comments

  1. What does stack 1 and stack 2 function do?

    ReplyDelete
    Replies
    1. stack01 and stack02 is help us to reducing burst time by FIFO method......thanks .
      ##support us by follow us on google+ and subscribe on youtube.

      Delete
  2. what is the pnt, tm, noe, c, rqi and Btm...?

    ReplyDelete
  3. please how can i reduce the processes in your code

    ReplyDelete

Post a Comment

Popular posts from this blog

Shortest Remaining Time First (SRTF) Program in C++ || dot clu

Shortest Remaining Time First (SRTF) Program in C++ || dot clu Shortest Remaining Time First (SRTF) Shortest Remaining Time First (SRTF) Algorithm is preemptive version of Shortest Job First Algorithm. In this current process is executed until it is completed or a new process is added having lower burst time compare to the the remaining time for current process. SRTF algorithm may lead to starvation, if processes with lower burst time continues to add to cpu scheduler then the current process will never get a chance to get executed. For example consider the following table Process Arrival Time Burst Time P1 0 10 P2 1 6 P3 2 9 P4 3 4 At time t=0, Process P1 will start get executing as it is only the process present at that time. Then at t=1, Process P2 added to the CPU scheduler, at this time remaining time(Burst time) for Process P1 gets 9, as Burst time of P2 is less than the remaining time of other processes (for now there is only process P1) therefore process

C++ Program For PRIORITY WITH NON - PREEMPTIVE Scheduling Algorithm || dot clu

C++ Program For PRIORITY WITH  NON - PREEMPTIVE Scheduling Algorithm It is important to distinguish  preemptive  from  non - preemptive scheduling algorithms.  Preemption  means the operating system moves a process from running to ready without the process requesting it. Without  preemption , the system implements ``run to completion (or yield or block)''. Non-Preemptive Scheduling Non-Preemptive Scheduling means once a process starts its execution or the CPU is processing a specific process it cannot be halted or in other words we cannot preempt (take control) the CPU to some other process. A computer system implementing this cannot support the execution of process in a multi task fashion. It executes all the processes in a sequential manner. It is not practical as all processes are not of same priority and are not always known to the system in advance. Source Code: #include <iostream> using namespace std; int main() {     int n;     cout