Algo Os
Algo Os
Here's an algorithm that could help you Step 1 : Get the number of processes.
Step 2 : Get the burst time and service time for each of the processes.
Step 3 : Initially the waiting time of the 1st priority process is 0 and the total time of
the 1st priority process is the same as the service time of that process.
Step 4 : Calculate the total time and waiting time of the remaining process.
Step 5 : Waiting time of one process is the total time of the previous process.
Step 6 : Total time of a process is calculated by adding the waiting time and service
time of each process.
Step 7 : The total turnaround time can be calculated by adding all the total time of
each process.
Step 8 : Total TurnAround time is calculated by adding all total time of each process.
Step 9 : avg.waiting time=total waiting time/total number of processes.
Step 10: avg.TurnAround time=total TurnAround time/number of processes.
Hope this helps.
Fcfs
#include<iostream>
using namespace std;
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
cout<<"Enter total number of processes(maximum 20):";
cin>>n;
cout<<"\nEnter Process Burst Time\n";
for(i=0;i<n;i++)
{
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
}
wt[0]=0;
Priority
#include<iostream>
using namespace std;
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
cout<<"Enter Total Number of Process:";
cin>>n;
cout<<"\nEnter Burst Time and Priority\n";
for(i=0;i<n;i++)
{
cout<<"\nP["<<i+1<<"]\n";
cout<<"Burst Time:";
cin>>bt[i];
cout<<"Priority:";
cin>>pr[i];
p[i]=i+1;
//contains process number
}
//sorting burst time, priority and process number in ascending order using
selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;