SlideShare a Scribd company logo
1 of 5
Download to read offline
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

Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediateMD. MARUFUZZAMAN .
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in pythonLifna C.S
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
Mobile computing : Indirect TCP
Mobile computing : Indirect TCPMobile computing : Indirect TCP
Mobile computing : Indirect TCPSushant Kushwaha
 
Back propagation
Back propagationBack propagation
Back propagationNagarajan
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default argumentsNikhil Pandit
 
Breadth first search (bfs)
Breadth first search (bfs)Breadth first search (bfs)
Breadth first search (bfs)Bishal Bhandari
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluationJeeSa Sultana
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxPrakash Zodge
 

What's hot (20)

Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediate
 
Introduction to Node MCU
Introduction to Node MCUIntroduction to Node MCU
Introduction to Node MCU
 
Heaps
HeapsHeaps
Heaps
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
Fuzzy neural networks
Fuzzy neural networksFuzzy neural networks
Fuzzy neural networks
 
Heapsort using Heap
Heapsort using HeapHeapsort using Heap
Heapsort using Heap
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Mobile computing : Indirect TCP
Mobile computing : Indirect TCPMobile computing : Indirect TCP
Mobile computing : Indirect TCP
 
Back propagation
Back propagationBack propagation
Back propagation
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Breadth first search (bfs)
Breadth first search (bfs)Breadth first search (bfs)
Breadth first search (bfs)
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
 

More from 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 SortBhavik Vashi
 
File management in OS
File management in OSFile management in OS
File management in OSBhavik 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 switchesBhavik Vashi
 
Fiscal Policy & Monetary Policy
Fiscal Policy & Monetary PolicyFiscal Policy & Monetary Policy
Fiscal Policy & Monetary PolicyBhavik Vashi
 
Projection of lines
Projection of linesProjection of lines
Projection of linesBhavik 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 WorldBhavik 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 mediaBhavik 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