Operating System
Operating System
Operating System
#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++)
} cin>>bt[i];cout<<"P["<<i+1<<"]:";
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j
++)
wt[i]+=bt[j];
}
cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround
Time"; for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
} cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];
avwt/=i;
avtat/=i;
cout<<"\n\nAverage Waiting Time:"<<avwt;
cout<<"\nAverage Turnaround Time:"<<avtat;
} return 0;
1
OUTPUT:
2
PROGRAM-02
#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,av
g_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;
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;
{
wt[i]=0;
for(j=0;j<i;j
++)
wt[i]+=bt[j];
3
total+=wt[i];
}
avg_wt=total/n;
total=0;
cout<<"\nProcess\t Burst Time \tWaiting Time\tTurnaround Time";
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
cout<<"\nP["<<p[i]<<"]\t\t"<<bt[i]<<"\t\t "<<wt[i]<<"\t\t\t"<<tat[i];
}
avg_tat=total/n;
cout<<"\n\nAverage Waiting Time="<<avg_wt;
cout<<"\nAverage Turnaround Time="<<avg_tat;
} return0;
OUTPUT:
4
PROGRAM-03
ALGORITHM:
#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,av
g_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;
}
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;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j
++)
wt[i]+=bt[j];
total+=wt[i];
}
5
avg_wt=total/n;
total=0;
cout<<"\nProcess\t Burst Time \tWaiting Time\tTurnaround Time";
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
cout<<"\nP["<<p[i]<<"]\t\t"<<bt[i]<<"\t\t "<<wt[i]<<"\t\t\t"<<tat[i];
}
avg_tat=total/n;
cout<<"\n\nAverage Waiting Time="<<avg_wt;
cout<<"\nAverage Turnaround Time="<<avg_tat;
} return 0;
OUTPUT:
6
PROGRAM-04
ALGORITHM:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int wtime[10],btime[10],rtime[10],num,quantum,total;
cout<<"Enter number of processes(MAX 10): ";
cin>>num;
cout<<"Enter burst time";
for(int i=0;i<num;i++)
{ cout<<"\nP["<<i+1<<"]: ";
cin>>btime[i];
rtime[i] = btime[i];
wtime[i]=0;
}
cout<<"\n\nEnter quantum: "; cin>>quantum;
int rp = num;
int i=0;
int time=0;
cout<<"0"; wtime[0]=0; while(rp!=0) { if(rtime[i]>quantum)
{
rtime[i]=rtime[i]-quantum;
cout<<" | P["<<i+1<<"] | ";
time+=quantum;
cout<<time;
}
else if(rtime[i]<=quantum && rtime[i]>0)
{time+=rtime[i];
rtime[i]=rtime[i]-rtime[i];
cout<<" | P["<<i+1<<"] | ";
rp--;
}cout<<time;
i++;
if(i==num)
{
i=0;
}
}
getch();
return; }
7
OUTPUT
: