C++ Program For PRIORITY WITH PREEMPTIVE Scheduling Algorithm
Priority Based Scheduling
- Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems.
- Each process is assigned a priority. Process with highest priority is to be executed first and so on.
- Processes with same priority are executed on first come first served basis.
- Priority can be decided based on memory requirements, time requirements or any other resource requirement.
Priority Scheduling always selects the process(es) with the highest priority currently ready to run. If there is more than one process having the currently highest priority, you need a second scheduling algorithm to choose among these processes. Non-preemptive Priority Scheduling only selects a new process to run if the running process finished its work or yields (voluntarily) to the scheduler.
Preemptive Priority Scheduling is the same algorithm but if a new process having a higher priority than the currently running process arrives, it gets selected immediately. The new process has not to wait until the currently running process finishes or yields.
Source Code
- //C++ Program For PRIORITY WITH PREEMPTIVE Scheduling Algorithm
- #include<iostream>
- using namespace std;
- int main()
- {
- int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i;
- cout<<"Enter the number of process : ";
- cin>>n;
- cout<<"\n Enter process : time priorities \n";
- for(i=0;i<n;i++)
- {
- cout<<"\nProcess no : "<<i+1<<" : ";
- cin>>pt[i]>>pp[i];
- p[i]=i+1;
- }
- for(i=0;i<n-1;i++)
- {
- for(int j=i+1;j<n;j++)
- {
- if(pp[i]<pp[j])
- {
- x=pp[i];
- pp[i]=pp[j];
- pp[j]=x;
- x=pt[i];
- pt[i]=pt[j];
- pt[j]=x;
- x=p[i];
- p[i]=p[j];
- p[j]=x;
- }
- }
- }
- w[0]=0;
- awt=0;
- t[0]=pt[0];
- atat=t[0];
- for(i=1;i<n;i++)
- {
- w[i]=t[i-1];
- awt+=w[i];
- t[i]=w[i]+pt[i];
- atat+=t[i];
- }
- cout<<"\n\n Job \t Burst Time \t Wait Time \t Turn Around Time Priority \n";
- for(i=0;i<n;i++)
- cout<<"\n"<<"\t\t"<<p[i]<<"\t\t"<<pt[i]<<"\t\t"<<w[i]<<"\t\t"<<t[i]<<"\t\t"<<pp[i];
- awt/=n;
- atat/=n;
- cout<<"\n Average Wait Time : %d \n"<<awt;
- cout<<"\n Average Turn Around Time : %d \n"<<atat;
- return 0;
- }
dotclu
dot clu
=====Also Watch Our Video========
SJF-Shortest Job First or SJN (shortest job Next) || C++ program of SJF with input | dot clu
https://youtu.be/zXA3oS5p1UM
Get started With C || First Program in C || C tutorial || Hello world program in C || dot clu
link: https://youtu.be/Oqyoe1nJNjE
Install Virtual BOX in your PC | create Virtual Machine | downloading link in description || dot clu
link:https://youtu.be/x9ijUzOUyiY
How to Install Hyper V in windows 7?
link: https://youtu.be/Y64Dr3YNCSw
What is Bitcoin? || Earn Bitcoin money with your Android phone || 100% working || dot clu || Hindi
link: https://youtu.be/HYQgDQrSC1I
dot clu
=====Also Watch Our Video========
SJF-Shortest Job First or SJN (shortest job Next) || C++ program of SJF with input | dot clu
https://youtu.be/zXA3oS5p1UM
Get started With C || First Program in C || C tutorial || Hello world program in C || dot clu
link: https://youtu.be/Oqyoe1nJNjE
Install Virtual BOX in your PC | create Virtual Machine | downloading link in description || dot clu
link:https://youtu.be/x9ijUzOUyiY
How to Install Hyper V in windows 7?
link: https://youtu.be/Y64Dr3YNCSw
What is Bitcoin? || Earn Bitcoin money with your Android phone || 100% working || dot clu || Hindi
link: https://youtu.be/HYQgDQrSC1I
Comments
Post a Comment