SlideShare a Scribd company logo
Rate Monotonic Scheduling
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
int pnum=0,lcmno,p[2][100],cap[2][100];
int lcm(int a[],int n);
int gcd(int a, int b);
class pro
{
public:
void get()
{
fstream file("Input File.txt",ios::out | ios::in);
int t1;
string temp;
while (!file.eof())
{
file>>temp>>t1>>temp>>p[0][pnum]>>temp>>p[1][pnum];
pnum++;
}
pnum--;
file.close();
int temp1[100];
for(int i=0;i<pnum;i++)
{
temp1[i]=p[1][i];
}
lcmno=lcm(temp1,pnum);
}
void display(void )
{
cout<<"Process:t1t2t3t4t5n";
for(int i=0;i<2;i++)
{
for(int j=0;j<pnum;j++)
{
if(j==0 && i==0)
Page 1
Rate Monotonic Scheduling
{
cout<<"CPU TIME:t"<<p[i][j]<<"t";
}
else if(j==0 && i==1)
{
cout<<"Period:tt"<<p[i][j]<<"t";
}
else
{
cout<<p[i][j]<<"t";
}
}
cout<<"n";
}
cout<<"LCM:"<<lcmno<<endl;
}
int check()
{
int i,n=pnum;
float in=((float)1/(float)n);
float u=((n)*(pow(2.0,((float)1/(float)n))-1));
float ut=0;
for(i=0;i<pnum;i++)
{
ut=ut+((float)p[0][i]/(float)p[1][i]);
}
cout<<"Utilization Bond:"<<u;
cout<<"nTotal Utilization Time:"<<ut;
if(u>ut)
return 1;
else
return 0;
}
};
int priority();
void sch();
int lcm(int a[],int n)
{
int ans = a[0];
for (int i = 1; i < n; i++)
{
ans = (((a[i] * ans)) /(gcd(a[i], ans)));
}
Page 2
Rate Monotonic Scheduling
return ans;
}
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int priority()
{
int p=-1,lessp=lcmno;
{
for(int i=0;i<pnum;i++)
{
if(cap[0][i]!=0)
{
if(lessp>cap[1][i])
{
p=i;
lessp=cap[1][i];
}
}
}
}
return p;
}
void sch()
{
fstream file("Output File.txt",ios::out );
int t,pr,i;
for(i=0;i<pnum;i++)
{
cap[0][i]=p[0][i];
cap[1][i]=p[1][i];
}
for(t=0;t<lcmno;t++)
{
for(i=0;i<pnum;i++)
{
if(cap[0][i]>cap[1][i])
{
cout<<"System is not scheduablen";
return;
Page 3
Rate Monotonic Scheduling
}
}
pr=priority();
if(pr!=-1)
{
file<<t<<"-"<<t+1<<"|Process:"<<pr+1<<endl;
}
else
{
file<<t<<"-"<<t+1<<endl;
}
cap[0][pr]--;
for(i=0;i<pnum;i++)
{
cap[1][i]--;
if(cap[1][i]==0)
{
cap[0][i]=p[0][i];
cap[1][i]=p[1][i];
}
}
}
file.close();
}
int main()
{
pro ob1;
ob1.get();
ob1.display();
int c=ob1.check();
if(c==0)
{
cout<<"nScheduling is not possiblen";
}
else
{
cout<<"nScheduling is possiblen";
sch();
}
return 0;
}
Page 4
Rate Monotonic Scheduling
Page 5

More Related Content

What's hot

Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manualPrabhu D
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
kulk0003
 
Bch and reed solomon codes generation in frequency domain
Bch and reed solomon codes generation in frequency domainBch and reed solomon codes generation in frequency domain
Bch and reed solomon codes generation in frequency domain
Madhumita Tamhane
 
Complex integration its uses and types
Complex integration its uses and typesComplex integration its uses and types
Complex integration its uses and types
SohailAkbar14
 
Dsp U Lec10 DFT And FFT
Dsp U   Lec10  DFT And  FFTDsp U   Lec10  DFT And  FFT
Dsp U Lec10 DFT And FFT
taha25
 
Fft analysis
Fft analysisFft analysis
Fft analysis
Satrious
 
Convolution sum using graphical and matrix method
Convolution sum using graphical and matrix methodConvolution sum using graphical and matrix method
Convolution sum using graphical and matrix method
Dr.SHANTHI K.G
 
mpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psimpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psi
hexiay
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
Mohammad Golyani
 
DDPG algortihm for angry birds
DDPG algortihm for angry birdsDDPG algortihm for angry birds
DDPG algortihm for angry birds
Wangyu Han
 
Digital System Processing
Digital System Processing Digital System Processing
Digital System Processing
Muhammad Zubair
 
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsDSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
Amr E. Mohamed
 
Properties of dft
Properties of dftProperties of dft
Properties of dft
tamil arasan
 
Engineering Electromagnetics 8th Edition Hayt Solutions Manual
Engineering Electromagnetics 8th Edition Hayt Solutions ManualEngineering Electromagnetics 8th Edition Hayt Solutions Manual
Engineering Electromagnetics 8th Edition Hayt Solutions Manual
xoreq
 
Verilog coding of demux 8 x1
Verilog coding of demux  8 x1Verilog coding of demux  8 x1
Verilog coding of demux 8 x1
Rakesh kumar jha
 
Digital Filters Part 1
Digital Filters Part 1Digital Filters Part 1
Digital Filters Part 1
Premier Farnell
 
EC8562 DSP Viva Questions
EC8562 DSP Viva Questions EC8562 DSP Viva Questions
EC8562 DSP Viva Questions
ssuser2797e4
 
Complex analysis notes
Complex analysis notesComplex analysis notes
Complex analysis notes
Prakash Dabhi
 

What's hot (20)

Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
 
Bch and reed solomon codes generation in frequency domain
Bch and reed solomon codes generation in frequency domainBch and reed solomon codes generation in frequency domain
Bch and reed solomon codes generation in frequency domain
 
Complex integration its uses and types
Complex integration its uses and typesComplex integration its uses and types
Complex integration its uses and types
 
Dsp U Lec10 DFT And FFT
Dsp U   Lec10  DFT And  FFTDsp U   Lec10  DFT And  FFT
Dsp U Lec10 DFT And FFT
 
Fft analysis
Fft analysisFft analysis
Fft analysis
 
Convolution sum using graphical and matrix method
Convolution sum using graphical and matrix methodConvolution sum using graphical and matrix method
Convolution sum using graphical and matrix method
 
mpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psimpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psi
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
 
DDPG algortihm for angry birds
DDPG algortihm for angry birdsDDPG algortihm for angry birds
DDPG algortihm for angry birds
 
Digital System Processing
Digital System Processing Digital System Processing
Digital System Processing
 
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsDSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
 
Properties of dft
Properties of dftProperties of dft
Properties of dft
 
Ft3 new
Ft3 newFt3 new
Ft3 new
 
Engineering Electromagnetics 8th Edition Hayt Solutions Manual
Engineering Electromagnetics 8th Edition Hayt Solutions ManualEngineering Electromagnetics 8th Edition Hayt Solutions Manual
Engineering Electromagnetics 8th Edition Hayt Solutions Manual
 
Verilog coding of demux 8 x1
Verilog coding of demux  8 x1Verilog coding of demux  8 x1
Verilog coding of demux 8 x1
 
Digital Filters Part 1
Digital Filters Part 1Digital Filters Part 1
Digital Filters Part 1
 
EC8562 DSP Viva Questions
EC8562 DSP Viva Questions EC8562 DSP Viva Questions
EC8562 DSP Viva Questions
 
Complex analysis notes
Complex analysis notesComplex analysis notes
Complex analysis notes
 

More from Bhavik Vashi

Aws ec2
Aws ec2Aws ec2
Aws ec2
Bhavik Vashi
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
Bhavik Vashi
 
Cloud computing
Cloud computingCloud computing
Cloud computing
Bhavik Vashi
 
Linear Sorting
Linear SortingLinear Sorting
Linear Sorting
Bhavik Vashi
 
Colormodels
ColormodelsColormodels
Colormodels
Bhavik Vashi
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
Bhavik Vashi
 
Runge Kutta Method
Runge Kutta Method Runge Kutta Method
Runge Kutta Method
Bhavik Vashi
 
Data Structure Radix Sort
Data Structure Radix SortData Structure Radix Sort
Data Structure Radix Sort
Bhavik Vashi
 
File management in OS
File management in OSFile management in OS
File management in OS
Bhavik Vashi
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
Bhavik Vashi
 
Parallel processing (simd and mimd)
Parallel processing (simd and mimd)Parallel processing (simd and mimd)
Parallel processing (simd and mimd)
Bhavik Vashi
 
Ethernet and switches
Ethernet and switchesEthernet and switches
Ethernet and switches
Bhavik Vashi
 
Fiscal Policy & Monetary Policy
Fiscal Policy & Monetary PolicyFiscal Policy & Monetary Policy
Fiscal Policy & Monetary Policy
Bhavik Vashi
 
Diwali Light
Diwali LightDiwali Light
Diwali Light
Bhavik Vashi
 
Heat transfer
Heat transferHeat transfer
Heat transfer
Bhavik Vashi
 
Projection of lines
Projection of linesProjection of lines
Projection of lines
Bhavik Vashi
 
Most Successful People & Personality
Most Successful People & Personality Most Successful People & Personality
Most Successful People & Personality
Bhavik Vashi
 
Global Need of the World
Global Need of the WorldGlobal Need of the World
Global Need of the World
Bhavik Vashi
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
Impact of social media
Impact of social mediaImpact of social media
Impact of social media
Bhavik Vashi
 

More from Bhavik Vashi (20)

Aws ec2
Aws ec2Aws ec2
Aws ec2
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Linear Sorting
Linear SortingLinear Sorting
Linear Sorting
 
Colormodels
ColormodelsColormodels
Colormodels
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Runge Kutta Method
Runge Kutta Method Runge Kutta Method
Runge Kutta Method
 
Data Structure Radix Sort
Data Structure Radix SortData Structure Radix Sort
Data Structure Radix Sort
 
File management in OS
File management in OSFile management in OS
File management in OS
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
 
Parallel processing (simd and mimd)
Parallel processing (simd and mimd)Parallel processing (simd and mimd)
Parallel processing (simd and mimd)
 
Ethernet and switches
Ethernet and switchesEthernet and switches
Ethernet and switches
 
Fiscal Policy & Monetary Policy
Fiscal Policy & Monetary PolicyFiscal Policy & Monetary Policy
Fiscal Policy & Monetary Policy
 
Diwali Light
Diwali LightDiwali Light
Diwali Light
 
Heat transfer
Heat transferHeat transfer
Heat transfer
 
Projection of lines
Projection of linesProjection of lines
Projection of lines
 
Most Successful People & Personality
Most Successful People & Personality Most Successful People & Personality
Most Successful People & Personality
 
Global Need of the World
Global Need of the WorldGlobal Need of the World
Global Need of the World
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
Impact of social media
Impact of social mediaImpact of social media
Impact of social media
 

Rate monotonic scheduling- Operating System

  • 1. Rate Monotonic Scheduling #include<iostream> #include<fstream> #include<algorithm> using namespace std; #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<math.h> int pnum=0,lcmno,p[2][100],cap[2][100]; int lcm(int a[],int n); int gcd(int a, int b); class pro { public: void get() { fstream file("Input File.txt",ios::out | ios::in); int t1; string temp; while (!file.eof()) { file>>temp>>t1>>temp>>p[0][pnum]>>temp>>p[1][pnum]; pnum++; } pnum--; file.close(); int temp1[100]; for(int i=0;i<pnum;i++) { temp1[i]=p[1][i]; } lcmno=lcm(temp1,pnum); } void display(void ) { cout<<"Process:t1t2t3t4t5n"; for(int i=0;i<2;i++) { for(int j=0;j<pnum;j++) { if(j==0 && i==0) Page 1
  • 2. Rate Monotonic Scheduling { cout<<"CPU TIME:t"<<p[i][j]<<"t"; } else if(j==0 && i==1) { cout<<"Period:tt"<<p[i][j]<<"t"; } else { cout<<p[i][j]<<"t"; } } cout<<"n"; } cout<<"LCM:"<<lcmno<<endl; } int check() { int i,n=pnum; float in=((float)1/(float)n); float u=((n)*(pow(2.0,((float)1/(float)n))-1)); float ut=0; for(i=0;i<pnum;i++) { ut=ut+((float)p[0][i]/(float)p[1][i]); } cout<<"Utilization Bond:"<<u; cout<<"nTotal Utilization Time:"<<ut; if(u>ut) return 1; else return 0; } }; int priority(); void sch(); int lcm(int a[],int n) { int ans = a[0]; for (int i = 1; i < n; i++) { ans = (((a[i] * ans)) /(gcd(a[i], ans))); } Page 2
  • 3. Rate Monotonic Scheduling return ans; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int priority() { int p=-1,lessp=lcmno; { for(int i=0;i<pnum;i++) { if(cap[0][i]!=0) { if(lessp>cap[1][i]) { p=i; lessp=cap[1][i]; } } } } return p; } void sch() { fstream file("Output File.txt",ios::out ); int t,pr,i; for(i=0;i<pnum;i++) { cap[0][i]=p[0][i]; cap[1][i]=p[1][i]; } for(t=0;t<lcmno;t++) { for(i=0;i<pnum;i++) { if(cap[0][i]>cap[1][i]) { cout<<"System is not scheduablen"; return; Page 3
  • 4. Rate Monotonic Scheduling } } pr=priority(); if(pr!=-1) { file<<t<<"-"<<t+1<<"|Process:"<<pr+1<<endl; } else { file<<t<<"-"<<t+1<<endl; } cap[0][pr]--; for(i=0;i<pnum;i++) { cap[1][i]--; if(cap[1][i]==0) { cap[0][i]=p[0][i]; cap[1][i]=p[1][i]; } } } file.close(); } int main() { pro ob1; ob1.get(); ob1.display(); int c=ob1.check(); if(c==0) { cout<<"nScheduling is not possiblen"; } else { cout<<"nScheduling is possiblen"; sch(); } return 0; } Page 4