Advertisement
FaisalAhemdBijoy

priority cpu os schedule

Oct 29th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. /*
  2. 5
  3. 3 10
  4. 1 1
  5. 4 2
  6. 5 1
  7. 2 5
  8. */
  9.  
  10. /*
  11. Enter The process Number
  12. 4
  13. Enter The priority Number and burst time
  14. 3 20
  15. 2 5
  16. 10 7
  17. 4 15
  18. Top value pq: 2-> Position : 2-> Start time : 0 -> Finish time : 5
  19. Top value pq: 3-> Position : 1-> Start time : 5 -> Finish time : 25
  20. Top value pq: 4-> Position : 4-> Start time : 25 -> Finish time : 40
  21. Top value pq: 10-> Position : 3-> Start time : 40 -> Finish time : 47
  22. Avg Waiting time : 17.5
  23. Avg Turn around time : 29.25
  24. Throughput : 0.034188
  25. */
  26. #include<bits/stdc++.h>
  27. using namespace std;
  28. priority_queue <pair<int,pair<int,int > > >pq;
  29. int main()
  30. {
  31.     int num,bt,prior,waiting=0,turnaround=0;
  32.     cout<<"Enter The process Number "<<endl;
  33.     cin>>num;
  34.     cout<<"Enter The priority Number and burst time "<<endl;
  35.     int ans[num+10],totaltime=0,sumtime=0;
  36.     for (int i=0; i<num; i++)
  37.     {
  38.         cin>>prior>>bt;
  39.         pq.push(make_pair(-1*prior,make_pair(bt,i))) ;
  40.     }
  41.  
  42.  
  43.     while(!pq.empty())
  44.     {
  45.         pair<int,pair<int,int> >t=pq.top();
  46.         int pos=t.second.second;
  47.         totaltime=t.second.first;
  48.         cout<<"Top value pq: "<<-1*t.first<<"-> Position : "<<pos+1<<"-> Start time : "<<sumtime<<" ";
  49.         waiting=waiting+sumtime;
  50.         sumtime=sumtime+totaltime;
  51.         cout<<"-> Finish time : "<<sumtime<<endl;
  52.         turnaround=turnaround+sumtime;
  53.  
  54.         pq.pop();
  55.  
  56.     }
  57.     cout<<"Avg Waiting time : "<<1.0* waiting/num<<endl;
  58.     cout<<"Avg Turn around time : "<<1.0*turnaround/num<<endl;
  59.     cout<<"Throughput : "<<1.0*num/turnaround<<endl;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement