#include <iostream>
#include<fstream>
using namespace std;
void writeFile(char fname[],int n)
{ fstream fwrite;
fwrite.open(fname,ios::out);
float a,b,p;
for(int i=0;i<n;i++)
{ cout<<"enter arival time :";
cin>>a;
cout<<endl<<"enter brust time:";
cin>>b;
cout<<endl<<"enter prority time:";
cin>>p;
fwrite<<i<<endl<<a<<endl<<b<<endl<<p<<endl;
}
fwrite.close();
}
void readFile(char fname[],int n)
{ fstream fread;
fread.open(fname,ios::in);
float total,wait[n];
float p[n],twaiting=0,waiting=0;
int proc;
int stack[n];
float brust[n],arrival[n],sbrust,temp[n],top=n,prority[n];
int i;
for( i=0;i<n;i++)
{ stack[i]=i;
fread>>p[i]>>arrival[i]>>brust[i]>>prority[i];
temp[i]=arrival[i];
sbrust=brust[i]+sbrust;
}
fread.close();
for(i=0;i<sbrust;i++)
{ proc=stack[0];
if(temp[proc]==i)
twaiting=0;
else
twaiting=i-(temp[proc]);
temp[proc]=i+1;
wait[proc]=wait[proc]+twaiting;
waiting=waiting+(twaiting);
brust[proc]=brust[proc]-1;
if(brust[proc]==0)
{
for(int x=0;x<top-1;x++)
{
stack[x]=stack[x+1];
}
top=top-1;
}
for(int z=0;z<top-1;z++)
{
if((prority[stack[0]]>prority[stack[z+1]]) && (arrival[stack[z+1]] <= i+1))
{
int t=stack[0];
stack[0]=stack[z+1];
stack[z+1]=t;
}
}
}
cout<<"waiting:"<<waiting;
float tu=(sbrust+waiting)/n;
cout<<endl<<"Average turnaround time is:"<<tu;
}
int main()
{
int n;
char fname[100];
cout<<"enter your toal no. of process";
cin>>n;
cout<<"enter your file name";
cin>>fname;
writeFile(fname,n);
readFile(fname,n);
return 0;
}
Various Process Scheduling Algorithms:
#include<fstream>
using namespace std;
void writeFile(char fname[],int n)
{ fstream fwrite;
fwrite.open(fname,ios::out);
float a,b,p;
for(int i=0;i<n;i++)
{ cout<<"enter arival time :";
cin>>a;
cout<<endl<<"enter brust time:";
cin>>b;
cout<<endl<<"enter prority time:";
cin>>p;
fwrite<<i<<endl<<a<<endl<<b<<endl<<p<<endl;
}
fwrite.close();
}
void readFile(char fname[],int n)
{ fstream fread;
fread.open(fname,ios::in);
float total,wait[n];
float p[n],twaiting=0,waiting=0;
int proc;
int stack[n];
float brust[n],arrival[n],sbrust,temp[n],top=n,prority[n];
int i;
for( i=0;i<n;i++)
{ stack[i]=i;
fread>>p[i]>>arrival[i]>>brust[i]>>prority[i];
temp[i]=arrival[i];
sbrust=brust[i]+sbrust;
}
fread.close();
for(i=0;i<sbrust;i++)
{ proc=stack[0];
if(temp[proc]==i)
twaiting=0;
else
twaiting=i-(temp[proc]);
temp[proc]=i+1;
wait[proc]=wait[proc]+twaiting;
waiting=waiting+(twaiting);
brust[proc]=brust[proc]-1;
if(brust[proc]==0)
{
for(int x=0;x<top-1;x++)
{
stack[x]=stack[x+1];
}
top=top-1;
}
for(int z=0;z<top-1;z++)
{
if((prority[stack[0]]>prority[stack[z+1]]) && (arrival[stack[z+1]] <= i+1))
{
int t=stack[0];
stack[0]=stack[z+1];
stack[z+1]=t;
}
}
}
cout<<"waiting:"<<waiting;
float tu=(sbrust+waiting)/n;
cout<<endl<<"Average turnaround time is:"<<tu;
}
int main()
{
int n;
char fname[100];
cout<<"enter your toal no. of process";
cin>>n;
cout<<"enter your file name";
cin>>fname;
writeFile(fname,n);
readFile(fname,n);
return 0;
}
Various Process Scheduling Algorithms:
- First come First served Scheduling Algorithm
- Non preemptive Shortest job first (SJF) scheduling Algorithm
- preemptive shortest job first (SJF) scheduling algorithm
- Non preemptive priority scheduling algorithm
- preemptive priority scheduling algorithm
- Roun Robin scheduling Algorithm
Various Page Replacement Algorithms:
- Page replacement using Least Recently Used (LRU) algorithm techneques.
- Page replacement using First come first served algorithm techniques.
Various Disk Head Movement Counting Algorithms:
- Count the disk head movement using first come first served (FCFS) algorithm
- head movement count using shortest seek job first (SSJF)
- head movement count using scan scheduling algorithm
- head movement count using c-scan scheduling algorithm
- head movement count using loop scheduling algorithm
- head movement count using c-loop scheduling alogrithm
No comments:
Post a Comment