Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 4
- 53
- 17
- 68
- 24
- 20
- */
- /*
- Round Robin CPU Scheduling
- Enter The process Number
- 4
- Enter The burst time
- 53
- 17
- 68
- 24
- Enter The quantum time
- 20
- Process : 0 Burst time :53
- Process : 1 Burst time :17
- Process : 2 Burst time :68
- Process : 3 Burst time :24
- calculation start
- process : 0 burst time :33
- process : 1 burst time :0
- process : 2 burst time :48
- process : 3 burst time :4
- process : 0 burst time :13
- process : 2 burst time :28
- process : 3 burst time :0
- process : 0 burst time :0
- process : 2 burst time :8
- process : 2 burst time :0
- */
- #include<bits/stdc++.h>
- using namespace std;
- int location[100];
- vector<pair<int,int > >v;
- int main()
- {
- cout<<"Round Robin CPU Scheduling "<<endl;
- int num,burst;
- cout<<"Enter The process Number"<<endl;
- cin>>num;
- vector<pair<int,int> >ans;
- cout<<"Enter The burst time "<<endl;
- for(int i=0; i<num; i++)
- {
- cin>>burst;
- v.push_back(make_pair(i,burst));
- }
- int quantum,now=0;
- cout<<"Enter The quantum time"<<endl;
- cin>>quantum;
- for (int i=0; i<num; i++)
- {
- cout<<"Process : "<<v[i].first<<" Burst time :"<<v[i].second<<endl;
- }
- bool flag=0;
- cout<<"calculation start"<<endl;
- int sum=0;
- while (1)
- {
- flag=0;
- for (int i=0,j=now; i<num; j++, i++)
- {
- j%=num;
- flag=0;
- if(v[j].second >0 )
- {
- flag=1;
- ans.push_back(make_pair(j,sum));
- sum=sum+min(quantum,v[j].second);
- v[j].second= v[j].second- min(quantum,v[j].second);
- cout<<"process : "<<j<<" burst time :"<<v[j].second<<endl;
- now=j+1;
- break;
- }
- }
- if (flag==0)
- {
- break;
- }
- }
- cout<<"Sequence"<<endl;
- for (int i=0; i<ans.size(); i++)
- {
- cout<<"P: "<<ans[i].first<<"->"<<ans[i].second<<endl;
- }
- cout<<endl;
- for (int i=0;i<ans.size();i++)
- {
- for (int j=0;j<num;j++){
- if(ans[i].first == j)
- {
- location[j]+=1;
- }
- }
- }
- cout<<"location"<<endl;
- for (int i=0;i<num;i++){
- cout<<location[i]<<" -> ";
- }
- cout<<endl;
- }
- /*
- Round Robin CPU Scheduling
- Enter The process Number
- 4
- Enter The burst time
- 53
- 17
- 68
- 24
- Enter The quantum time
- 20
- Process : 0 Burst time :53
- Process : 1 Burst time :17
- Process : 2 Burst time :68
- Process : 3 Burst time :24
- calculation start
- process : 0 burst time :33
- process : 1 burst time :0
- process : 2 burst time :48
- process : 3 burst time :4
- process : 0 burst time :13
- process : 2 burst time :28
- process : 3 burst time :0
- process : 0 burst time :0
- process : 2 burst time :8
- process : 2 burst time :0
- Sequence
- P: 0->20
- P: 1->37
- P: 2->57
- P: 3->77
- P: 0->97
- P: 2->117
- P: 3->121
- P: 0->134
- P: 2->154
- P: 2->162
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement