world-of-c-programming.blogspot.in - OS Lab









Search Preview

World of C Programming: OS Lab

world-of-c-programming.blogspot.in
This is an try to put the solutions of all problems related to C and C++. Labs: DSA, DAA, OS, Graphics, Compiler, Network. Extra: PROBLEMS, FORUM.
.in > world-of-c-programming.blogspot.in

SEO audit: Content analysis

Language Error! No language localisation is found.
Title World of C Programming: OS Lab
Text / HTML ratio 24 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud page = pages frame void frames Lab OS number int index algorithm printfEnter < program distances == wt numberFrames temp
Keywords consistency
Keyword Content Title Description Headings
page 63
= 62
pages 37
frame 37
void 34
frames 34
Headings
H1 H2 H3 H4 H5 H6
1 10 14 0 0 0
Images We found 33 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
page 63 3.15 %
= 62 3.10 %
pages 37 1.85 %
frame 37 1.85 %
void 34 1.70 %
frames 34 1.70 %
Lab 33 1.65 %
OS 28 1.40 %
number 28 1.40 %
int 28 1.40 %
index 28 1.40 %
algorithm 23 1.15 %
printfEnter 19 0.95 %
< 17 0.85 %
program 17 0.85 %
distances 16 0.80 %
== 16 0.80 %
wt 16 0.80 %
numberFrames 16 0.80 %
temp 16 0.80 %

SEO Keywords (Two Word)

Keyword Occurrence Density
number of 28 1.40 %
1 1 17 0.85 %
OS Lab 16 0.80 %
= 1 14 0.70 %
3 3 14 0.70 %
of pages 14 0.70 %
For every 14 0.70 %
Mangi Lal 13 0.65 %
Lal Sharma 13 0.65 %
to TwitterShare 12 0.60 %
ThisBlogThisShare to 12 0.60 %
TwitterShare to 12 0.60 %
by Mangi 12 0.60 %
to FacebookShare 12 0.60 %
Email ThisBlogThisShare 12 0.60 %
comments Email 12 0.60 %
FacebookShare to 12 0.60 %
at 11282012 12 0.60 %
Labels OS 12 0.60 %
Sharma at 12 0.60 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
Mangi Lal Sharma 13 0.65 % No
to Pinterest Labels 12 0.60 % No
ThisBlogThisShare to TwitterShare 12 0.60 % No
1 1 1 12 0.60 % No
Labels OS Lab 12 0.60 % No
Pinterest Labels OS 12 0.60 % No
FacebookShare to Pinterest 12 0.60 % No
TwitterShare to FacebookShare 12 0.60 % No
to TwitterShare to 12 0.60 % No
to FacebookShare to 12 0.60 % No
Email ThisBlogThisShare to 12 0.60 % No
comments Email ThisBlogThisShare 12 0.60 % No
Sharma at 11282012 12 0.60 % No
Lal Sharma at 12 0.60 % No
by Mangi Lal 12 0.60 % No
Posted by Mangi 12 0.60 % No
number of frames 10 0.50 % No
written by Mars 10 0.50 % No
program written by 10 0.50 % No
getch program written 9 0.45 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
FacebookShare to Pinterest Labels 12 0.60 % No
by Mangi Lal Sharma 12 0.60 % No
to FacebookShare to Pinterest 12 0.60 % No
TwitterShare to FacebookShare to 12 0.60 % No
to TwitterShare to FacebookShare 12 0.60 % No
ThisBlogThisShare to TwitterShare to 12 0.60 % No
Email ThisBlogThisShare to TwitterShare 12 0.60 % No
comments Email ThisBlogThisShare to 12 0.60 % No
Lal Sharma at 11282012 12 0.60 % No
Mangi Lal Sharma at 12 0.60 % No
Posted by Mangi Lal 12 0.60 % No
to Pinterest Labels OS 12 0.60 % No
Pinterest Labels OS Lab 12 0.60 % No
program written by Mars 10 0.50 % No
getch program written by 9 0.45 % No
lab Posted by Mangi 8 0.40 % No
OS lab Posted by 8 0.40 % No
1 1 1 1 8 0.40 % No
j < numberFrames j 8 0.40 % No
= j < numberFrames 8 0.40 % No

Internal links in - world-of-c-programming.blogspot.in

Welcome
World of C Programming: Welcome
C basic lab
World of C Programming: C basic lab
C++ basic Lab
World of C Programming: C++ basic lab
DSA Lab
World of C Programming: DSA Lab
DAA Lab
World of C Programming: DAA Lab
OS Lab
World of C Programming: OS Lab
Graphics Lab
World of C Programming: Graphics Lab
Compiler Lab
World of C Programming: Compiler Lab
Network Lab
World of C Programming: Network Lab
PROBLEMS
World of C Programming: PROBLEMS
FORUM
World of C Programming: FORUM

World-of-c-programming.blogspot.in Spined HTML


World of C Programming: OS Lab World of C Programming This is a try to put the solutions of each possible problem related to C and C++. You can find here C vital lab, C++ vital Lab, Data Structure Lab, DAA Lab, Operating System Lab, Graphics Lab, Compiler Lab, Network Lab, and other problems. Pages Home Welcome C vital lab C++ vital Lab DSA Lab DAA Lab OS Lab Graphics Lab Compiler Lab Network Lab PROBLEMS FORUM Showing posts with label OS Lab. Show all posts Showing posts with label OS Lab. Show all posts Wednesday, 28 November 2012 Shortest job first (SJF) scheduling algorithm //Shortest job first (SJF) scheduling algorithm implementation using C++ #include"iostream.h" #include"conio.h" #include"string.h" int total,i,n; bladder avg; matriculation sjf {  int t,bt[12],wt[12];  char p[12][6],tp[6];  public:  sjf()  {   wt[0]=0;   total=0;   avg=0;  }  void input(int n);  void apply();  void display(); };  void sjf::input(int n)  {   for(i=0;i<n;i++)   {    cout<<"Enter process "<<i+1<<" name :";    cin>>p[i];    cout<<"Enter process time :";    cin>>bt[i];   }  }  void sjf::apply()  {   for(int i=0;i<n-1;i++)    for(int j=i+1;j<n;j++)     if(bt[i]>bt[j])     {      t=bt[j];      bt[j]=bt[i];      bt[i]=t;      strcpy(tp,p[j]);      strcpy(p[j],p[i]);      strcpy(p[i],tp);     }   for(i=1;i<n;i++)   {    wt[i]=wt[i-1]+bt[i-1];    total=total+wt[i];   }   avg=(float)total/n;  }  void sjf::display()  {   cout<<"P_name\tP_time\tW_time\n";   for(i=0;i<n;i++)   cout<<p[i]<<"\t"<<bt[i]<<"\t"<<wt[i]<<"\n";  } void main() {  sjf sjf;  clrscr();  cout<<"Enter no. of processes :";  cin>>n;  sjf.input(n);  sjf.apply();  sjf.display();  cout<<"total waiting time :"<<total<<"\n";  cout<<"Average waiting Time :"<<avg;  getch(); } //program written by Mars. 06/09/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:48:00 pm No comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab Round Robin scheduling algorithm //Round Robin scheduling algorithm implementation using C++ #include"iostream.h" #include"conio.h" #include"string.h" int total,i,j,n,m; bladder avg; matriculation fcfs {  int bt[12],wt[12],et[12],rt,timer,count,found;  char p[12][6];  public:  fcfs()  {   wt[0]=0;   total=0;   avg=0;  }  void input(int n);  void apply();  void display(); }; //program written by Mars. 20/09/2011. OS lab.  void fcfs::input(int n)  {   for(i=0;i<n;i++)   {    cout<<"Enter process "<<i+1<<" name :";    cin>>p[i];    cout<<"Enter process time :";    cin>>bt[i];    cout<<"enter splash time";    cin>>bt[i];   }  }  void fcfs:: apply()  {   timer=4;   m=n;   wt[0]=0; i=0; do { if(bt[i]>timer) { rt=bt[i]-timer; strcpy(p[n],p[i]); bt[n]=rt; et[i]=timer; n++; } else { et[i]=bt[i]; } i++; wt[i]=wt[i-1]+et[i-1]; } while(i<n); count=0; for(i=0;i<m;i++) { for(j=i+1;j<=n;j++) { if(strcmp(p[i],p[j])==0) { count++; found=j; } } if(found!=0) { wt[i]=wt[found]-(count*timer); count=0; found=0; } } for(i=0;i<m;i++) { total+=wt[i]; } avg=(float)total/m;  }  void fcfs::display()  {   cout<<"P_name\tP_time\tW_time\n";   for(i=0;i<n;i++)   cout<<p[i]<<"\t"<<bt[i]<<"\t"<<wt[i]<<"\n";  } void main() {  fcfs fcfs;  clrscr();  cout<<"Enter no. of processes :";  cin>>n;  fcfs.input(n);  fcfs.apply();  fcfs.display();  cout<<"total waiting time :"<<total<<"\n";  cout<<"Average waiting Time :"<<avg;  getch(); } Posted by Mangi Lal Sharma at 11/28/2012 05:47:00 pm No comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab Priority schduling algorithm //Priority schduling algorithm implementation using C++ #include"iostream.h" #include"conio.h" #include"string.h" int total,i,j,n,temp; bladder avg; matriculation priority {  int bt[12],wt[12],pr[12];  char p[12][6], tempc[5];  public:  priority()  {   wt[0]=0;   total=0;   avg=0;  }  void input(int n);  void apply();  void display(); };  void priority::input(int n)  {   for(i=0;i<n;i++)   {    cout<<"Enter process "<<i+1<<" name :";    cin>>p[i];    cout<<"EnterSplashtime :";    cin>>bt[i];    cout<<"enter priority :";    cin>>pr[i];   }  } void priority:: apply() {  for(i=0;i<n-1;i++)  {   for(j=i+1;j<n;j++)   {    if(pr[i]>pr[j])    {     temp=pr[i];     pr[i]=pr[j];     pr[j]=temp;     temp=bt[i];     bt[i]=bt[j];     bt[j]=temp;     strcpy(tempc,p[i]);     strcpy(p[i],p[j]);     strcpy(p[j],tempc);    }   }  }  wt[0]=0;  for(i=1;i<n;i++)  {   wt[i]=wt[i-1]+bt[i-1];   total=total+wt[i];  }  avg=(float)total/n;  for(i=1;i<n;i++)  {   wt[i]=wt[i-1]+bt[i-1];   total=total+wt[i];  }   avg=(float)total/n; }  void priority::display()  {   cout<<"P_name\tP_time\tW_time\tPriority\n";   for(i=0;i<n;i++)   cout<<p[i]<<"\t"<<bt[i]<<"\t"<<wt[i]<<"\t"<<pr[i]<<"\n";  } void main() {  priority priority;  clrscr();  cout<<"Enter no. of processes :";  cin>>n;  priority.input(n);  priority.apply();  priority.display();  cout<<"total waiting time :"<<total<<"\n";  cout<<"Average waiting Time :"<<avg;  getch(); } //program written by Mars. 20/09/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:45:00 pm No comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab First Come First Serve (FCFS) scheduling algorithm //First Come First Serve (FCFS) scheduling algorithm implementation using C++ #include"iostream.h" #include"conio.h" int total,i,n; bladder avg; matriculation fcfs {  int bt[12],wt[12];  char p[12][6];  public:  fcfs()  {   wt[0]=0;   total=0;   avg=0;  }  void input(int n);  void apply();  void display(); };  void fcfs::input(int n)  {   for(i=0;i<n;i++)   {    cout<<"Enter process "<<i+1<<" name :";    cin>>p[i];    cout<<"Enter process time :";    cin>>bt[i];   }  }  void fcfs:: apply()  {   for(i=1;i<n;i++)   {    wt[i]=wt[i-1]+bt[i-1];    total=total+wt[i];   }   avg=(float)total/n;  }  void fcfs::display()  {   cout<<"P_name\tP_time\tW_time\n";   for(i=0;i<n;i++)   cout<<p[i]<<"\t"<<bt[i]<<"\t"<<wt[i]<<"\n";  } void main() {  fcfs fcfs;  clrscr();  cout<<"Enter no. of processes :";  cin>>n;  fcfs.input(n);  fcfs.apply();  fcfs.display();  cout<<"total waiting time :"<<total<<"\n";  cout<<"Average waiting Time :"<<avg;  getch(); } //program written by Mars. 06/09/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:43:00 pm 3 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab Deadlock Detection algorithm /* Banker's algorithm This is a deadlock avoidance/prevention algorithm ways avoid/prevent the happening of deadlock. This is a  resource typecasting algorithm ways intrust the resources in way in which deadlock should not occur. This is a deadlock detection algorithm ways if there is no way to prevent deadlock, then say deadlock occurred. This algorithm was ripened by Edsger Dijkstra. */ #include <stdio.h>; #include <conio.h>; void main() {  int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;  clrscr();  printf("Enter total no of processes");  scanf("%d",&tp);  printf("Enter total no of resources");  scanf("%d",&tr);  printf("Enter requirement (Max. Need) matrix\n");  for(i=1;i<=tp;i++)  {   printf("process %d:\n",i);   for(j=1;j<=tr;j++)   scanf("%d",&c[i][j]);  }  printf("Enter typecasting matrix\n");  for(i=1;i<=tp;i++)  {   printf("process %d:\n",i);   for(j=1;j<=tr;j++)   scanf("%d",&p[i][j]);  }  printf("Enter resource vector (Total resources):\n");  for(i=1;i<=tr;i++)  {   scanf("%d",&r[i]);  }  printf("Enter availability vector (available resources):\n");  for(i=1;i<=tr;i++)  {   scanf("%d",&a[i]);   temp[i]=a[i];  }  for(i=1;i<=tp;i++)  {   sum=0;   for(j=1;j<=tr;j++)   {    sum+=p[i][j];   }   if(sum==0)   {    m[k]=i;    k++;   }  }  for(i=1;i<=tp;i++)  {   for(l=1;l<k;l++)   if(i!=m[l])   {    flag=1;    for(j=1;j<=tr;j++)    if(c[i][j]<temp[j])    {     flag=0;     break;    }   }   if(flag==1)   {    m[k]=i;    k++;    for(j=1;j<=tr;j++)    temp[j]+=p[i][j];   }  }  printf("deadlock causing processes are:");  for(j=1;j<=tp;j++)  {   found=0;   for(i=1;i<k;i++)   {    if(j==m[i])    found=1;   }   if(found==0)   printf("%d\t",j);  }  getch(); } //program written by Mars. 27/11/2011. OS lab. Output- Enter total no. of processes : 4 Enter total no. of resources : 5 Enter requirement (Max. Need) matrix : 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1 Enter typecasting matrix : 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 Enter resource vector (Total resources) : 2 1 1 2 1 Enter availability vector (available resources) : 0 0 0 0 1 deadlock causing processes are : 2 3 Note- See the algorithm at: http://en.wikipedia.org/wiki/Banker%27s_algorithm Posted by Mangi Lal Sharma at 11/28/2012 05:30:00 pm 4 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab Worst fit memory management algorithm //WORST FIT MEMORY MANAGEMENT ALGORITHM IMPLEMENTATION #include<stdio.h> #include<conio.h> #define max 25 void main() {  int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;  static int bf[max],ff[max];  clrscr();  printf("\n\tMemory Management Scheme - Worst Fit");  printf("\nEnter the number of blocks:");  scanf("%d",&nb);  printf("Enter the number of files:");  scanf("%d",&nf);  printf("\nEnter the size of the blocks:-\n");  for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}  printf("Enter the size of the files :-\n");  for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}  for(i=1;i<=nf;i++)  {   for(j=1;j<=nb;j++)   {    if(bf[j]!=1)    //if bf[j] is not allocated    {     temp=b[j]-f[i];     if(temp>=0)     if(highest<temp)     {      ff[i]=j;      highest=temp;     }    }   }   frag[i]=highest;   bf[ff[i]]=1;   highest=0;  }  printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");  for(i=1;i<=nf;i++)  printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);  getch(); } //program written by Mars. 27/11/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:27:00 pm 3 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab First fit memory management algorithm //FIRST FIT MEMORY MANAGEMENT ALGORITHM IMPLEMENTATION #include<stdio.h> #include<conio.h> #define max 25 void main() {  int frag[max],b[max],f[max],i,j,nb,nf,temp;  static int bf[max],ff[max];  clrscr();  printf("\n\tMemory Management Scheme - First Fit");  printf("\nEnter the number of blocks:");  scanf("%d",&nb);  printf("Enter the number of files:");  scanf("%d",&nf);  printf("\nEnter the size of the blocks:-\n");  for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}  printf("Enter the size of the files :-\n");  for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}  for(i=1;i<=nf;i++)  {   for(j=1;j<=nb;j++)   {    if(bf[j]!=1)    {     temp=b[j]-f[i];     if(temp>=0)     {      ff[i]=j;      break;     }    }   }   frag[i]=temp;   bf[ff[i]]=1;  }  printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");  for(i=1;i<=nf;i++)  printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);  getch(); } //program written by Mars. 27/11/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:24:00 pm 2 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS LabWeightierfit memory management algorithm //BEST FIT MEMORY MANAGEMENT ALGORITHM IMPLEMENTATION #include<stdio.h> #include<conio.h> #define max 25 void main() {  int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;  static int bf[max],ff[max];  clrscr();  printf("\n\tMemory Management Scheme -WeightierFit");  printf("\nEnter the number of blocks:");  scanf("%d",&nb);  printf("Enter the number of files:");  scanf("%d",&nf);  printf("\nEnter the size of the blocks:-\n");  for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}  printf("Enter the size of the files :-\n");  for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}  for(i=1;i<=nf;i++)  {   for(j=1;j<=nb;j++)   {    if(bf[j]!=1)    {     temp=b[j]-f[i];     if(temp>=0)     if(lowest>temp)     {      ff[i]=j;      lowest=temp;     }    }   }   frag[i]=lowest;   bf[ff[i]]=1;   lowest=10000;  }  printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");  for(i=1;i<=nf && ff[i]!=0;i++) //line edited on 23/09/2013  printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);  getch(); } //program written by Mars. 27/11/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:21:00 pm 23 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab Optimal Page Replacement Algorithm - C Program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 /** * Optimal Page Replacement Algorithm - C program * @author Mangilal Sharma * Initial Edit: November 27, 2011 for OS lab * Last Modified: October 27, 2016 for http://world-of-c-programming.blogspot.in/ * * Description: * A page, memory page, or virtual page is a fixed-length first-hand woodcut of virtual memory. * A page frame is the smallest fixed-length first-hand woodcut of physical memory into which memory pages are mapped by the os. * A transfer of pages between main memory and an virtual memory happens. * The optimal page replacement algorithm, moreover known as Look Forward Technique, simply says that the page with less urgency in future should be removed. * * Example: * Given number of frames: 3 * Given number of pages: 12 * Required pages wangle sequence: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3 * 7 0 1 2 0 3 0 4 2 3 0 3 * Frame1 7 7 7 2 2 2 2 2 2 2 0 0 * Frame2 0 0 0 0 0 0 4 4 4 4 4 * Frame3 1 1 1 3 3 3 3 3 3 3 * Faults * * * * * * * * Number of page faults = 7 */ #include<stdio.h> #define MAX_PAGE 25 // Define a constant, program can support only this MAX_PAGE number of pages. #define MAX_FRAME 25 // Define a constant, program can support only this MAX_FRAME number of frames. /** * Function main returns 0 on success. */ int main() { // Declare arrays for pages and frames and distance_from_future_occurance int pages[MAX_PAGE], frames[MAX_FRAME], distances[MAX_PAGE]; // Number of pages, frames, page faults variables int numberPages, numberFrames, numberPageFaults = 0; // Other variables int i, j, temp, flag, found, lastFilledFrame, index, highestDistance; // Get number of frames from user printf("Enter number of frames (max limit is %d): ", MAX_FRAME); scanf("%d", &numberFrames); printf("You provided number of frames: %d\n", numberFrames); // Initialize frames variety with -1 values and set lastFilledFrame value to -1 for(i = 0; i < numberFrames; i++) frames[i] = -1; lastFilledFrame = -1; // Get pages from user printf("Enter pages (enter -999 to exit, max number of pages limit is %d):\n", MAX_PAGE); numberPages = 0; for(i = 0; i < MAX_PAGE; i++) { scanf("%d", &temp); if(temp == -999 || numberPages == MAX_PAGE) break; pages[i] = temp; numberPages++; } printf("You provided number of pages: %d\n", numberPages); // Traverse the sequence of pages equal Optimal Page Replacement Algorithm for(i = 0; i < numberPages; i++) // For every page { flag = 0; // Flag to show availability of page in frame // Get the availability of required page in frame for(j = 0; j < numberFrames; j++) // For every frame { if(frames[j] == pages[i]) // If page found in frame { flag = 1; // Set flag to 1, showing that page is misogynist in frame printf("\t"); // Print tab space instead "FAULT" word break; //Unravelthe loop } } // If page is not misogynist in frame, replace some page by required page and print "FAULT" word if(flag == 0) { if (lastFilledFrame == numberFrames-1) // If frames fully filled { // For every frame containing page, summate distances to future occurance for(j = 0; j < numberFrames; j++) { for(temp = i + 1; temp < numberPages; temp++) // For every future page { distances[j] = 0; // Set this page_occurances_in_future to zero, showing no occurance if (frames[j] == pages[temp]) // If frame containing page matches to future occuring page { distances[j] = temp - i; // Store loftiness break; } } // For every future page loop ends here } // Loop for gingerly distances ends here // Choose weightier candidate alphabetize for page replacement in frame, this weightier candidate is not occuring in future found = 0; for(j = 0; j < numberFrames; j++) // For every frame { if(distances[j] == 0) // If page's loftiness value is 0, ways if no occurance in future { // Or if frame value is -1, ways empty frame alphabetize = j; // Set this frame alphabetize to alphabetize variable found = 1; // Set to 1, ways a page not occuring in future is found break; } } } else // If frames has not fully filled, weightier candidate is zippo frame { alphabetize = ++lastFilledFrame; // Set zippo frame's alphabetize to alphabetize variable found = 1; // Set to 1, ways a suitable frame alphabetize found } // If still not choosed weightier candidate, get weightier candidate that is having highest loftiness in future if(found == 0) { highestDistance = distances[0]; alphabetize = 0; for(j = 1; j<numberFrames; j++) // For every frame { if(highestDistance < distances[j]) { highestDistance = distances[j]; alphabetize = j; // In last, alphabetize will contain farest distanced element's alphabetize in current frames } } } // Do the page replacement frames[index] = pages[i]; // Replace the identified alphabetize located page by required page printf("FAULT\t"); // Print "FAULT" numberPageFaults++; // Increment number of page faults } // Print the pages that are present in current frames for(j = 0; j < numberFrames; j++) { if(frames[j] != -1) printf("%d\t", frames[j]); } printf("\n"); } // Print number of page faults. printf("Number of page faults = %d\n", numberPageFaults); return 0; } Output Snapshot Posted by Mangi Lal Sharma at 11/28/2012 05:14:00 pm 10 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab LRU Page Replacement Algorithm - C Program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 /** * LRU (Least Recently Used) Page Replacement Algorithm - C program * @author Mangilal Sharma * Initial Edit: November 27, 2011 for OS lab * Last Modified: October 28, 2016 for http://world-of-c-programming.blogspot.in/ * * Description: * A page, memory page, or virtual page is a fixed-length first-hand woodcut of virtual memory. * A page frame is the smallest fixed-length first-hand woodcut of physical memory into which memory pages are mapped by the os. * A transfer of pages between main memory and an virtual memory happens. * The LRU page replacement algorithm, simply says that the page which used in least recent, should be replaced by required page. * * Example: * Given number of frames: 3 * Given number of pages: 12 * Required pages wangle sequence: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3 * 7 0 1 2 0 3 0 4 2 3 0 3 * Frame1 7 7 7 2 2 2 2 4 4 4 0 0 * Frame2 0 0 0 0 0 0 0 0 3 3 3 * Frame3 1 1 1 3 3 3 2 2 2 2 * Faults * * * * * * * * * * Number of page faults = 9 */ #include<stdio.h> #define MAX_PAGE 25 // Define a constant, program can support only this MAX_PAGE number of pages. #define MAX_FRAME 25 // Define a constant, program can support only this MAX_FRAME number of frames. /** * Function main returns 0 on success. */ int main() { // Declare arrays for pages and frames and distance_from_past_occurance int pages[MAX_PAGE], frames[MAX_FRAME], distances[MAX_FRAME]; // Number of pages, frames, page faults variables int numberPages, numberFrames, numberPageFaults = 0; // Other variables int i, j, temp, flag, found, lastFilledFrame, index, highestDistance; // Get number of frames from user printf("Enter number of frames (max limit is %d): ", MAX_FRAME); scanf("%d", &numberFrames); printf("You provided number of frames: %d\n", numberFrames); // Initialize frames variety with -1 values and set lastFilledFrame value to -1 for(i = 0; i < numberFrames; i++) frames[i] = -1; lastFilledFrame = -1; // Get pages from user printf("Enter pages (enter -999 to exit, max number of pages limit is %d):\n", MAX_PAGE); numberPages = 0; for(i = 0; i < MAX_PAGE; i++) { scanf("%d", &temp); if(temp == -999 || numberPages == MAX_PAGE) break; pages[i] = temp; numberPages++; } printf("You provided number of pages: %d\n", numberPages); // Traverse the sequence of pages equal LRU Page Replacement Algorithm for(i = 0; i < numberPages; i++) // For every page { flag = 0; // Flag to show availability of page in frame // Get the availability of required page in frame for(j = 0; j < numberFrames; j++) // For every frame { if(frames[j] == pages[i]) // If page found in frame { flag = 1; // Set flag to 1, showing that page is misogynist in frame printf("\t"); // Print tab space instead "FAULT" word break; //Unravelthe loop } } // If page is not misogynist in frame, replace some page by required page and print "FAULT" word if(flag == 0) { if (lastFilledFrame == numberFrames-1) // If frames fully filled { // For every frame containing page, summate distances to past occurance for(j = 0; j < numberFrames; j++) { for(temp = i - 1; temp > -1; temp--) // For every past page { distances[j] = 0; // Set this page_occurances_in_past to zero, showing no occurance if (frames[j] == pages[temp]) // If frame containing page matches to past occuring page { distances[j] = i - temp; // Store loftiness break; } } // For every past page loop ends here } // Loop for gingerly distances ends here // Choose weightier candidate alphabetize for page replacement in frame, this weightier candidate is not occuring in past found = 0; for(j = 0; j < numberFrames; j++) // For every frame { if(distances[j] == 0) // If page's loftiness value is 0, ways if no occurance in past { // Or if frame value is -1, ways empty frame alphabetize = j; // Set this frame alphabetize to alphabetize variable found = 1; // Set to 1, ways a page not occuring in past is found break; } } } else // If frames has not fully filled, weightier candidate is zippo frame { alphabetize = ++lastFilledFrame; // Set zippo frame's alphabetize to alphabetize variable found = 1; // Set to 1, ways a suitable frame alphabetize found } // If still not choosed weightier candidate, get weightier candidate that is having highest loftiness in past if(found == 0) { highestDistance = distances[0]; alphabetize = 0; for(j = 1; j<numberFrames; j++) // For every frame { if(highestDistance < distances[j]) { highestDistance = distances[j]; alphabetize = j; // In last, alphabetize will contain farest distanced element's alphabetize in current frames } } } // Do the page replacement frames[index] = pages[i]; // Replace the identified alphabetize located page by required page printf("FAULT\t"); // Print "FAULT" numberPageFaults++; // Increment number of page faults } // Print the pages that are present in current frames for(j = 0; j < numberFrames; j++) { if(frames[j] != -1) printf("%d\t", frames[j]); } printf("\n"); } // Print number of page faults. printf("Number of page faults = %d\n", numberPageFaults); return 0; } Snapshots Posted by Mangi Lal Sharma at 11/28/2012 05:09:00 pm 7 comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab FIFO page replacement algorithm //FIFO page replacement algorithm #include<stdio.h> #include<conio.h> #define max 25 void main() {  int frame[10];  int i,j,k,nf,np=0,page[max],temp;  int flag=0,pf=0,top=0;  clrscr();  printf("Enter no. of Frames:");  scanf("%d",&nf);  for(i=0;i<nf;i++)   frame[i]=-1;  printf("Enter pages (press -999 to exit):\n");  for(i=0;i<max;i++)  {   scanf("%d",&temp);   if(temp==-999) break;   page[i]=temp;   np++;  }  for(i=0;i<np;i++)  {   flag=0;   for(j=0;j<nf;j++)   {    if(frame[j]==page[i])    {     printf("\n\t");     flag=1;break;    }   }   if(flag==0)   {    frame[top]=page[i];    top++;    printf("\nFault:  ");    pf++;    if(top>=nf)    top=0;   }   for(k=0;k<nf;k++)   printf("%d\t",frame[k]);  }  printf("\nNumber of page faults is: %d ",pf);  getch(); } //program written by Mars. 27/11/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:07:00 pm No comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab FIFO Disk sheduling algorithm //FIFO-Disk sheduling implementation #include<stdio.h> #include<conio.h> #include<stdlib.h> int request[100],cylinders,st; int total=0,i,temp,n=0; void main() {  clrscr();  printf("\nEnter no. of cylinders in disk:");  scanf("%d",&cylinders);  printf("Enter starting cylinder:");  scanf("%d",&st);  printf("\nEnter the cylinders requested (-999 to break): \n");  while(1)  {   scanf("%d",&temp);   if (temp==-999) break;   request[n]=temp;   n++;  }  printf("\nThe requests are : \n");  for(i=0;i<n;i++)  printf(" %d" ,request[i]);  printf("\n\n The traversal is shown unelevated : \n\n%d",st);  for(i=0;i<n;i++)  {   printf("-->%d",request[i]);   total=total+abs(request[i]-st);     //abs provide difference in +ive unchangingly   st=request[i];  }  printf("\n\nNo. of cylinders traversed : %d",total);  getch(); } //program written by Mars. 28/11/2011. OS lab. Posted by Mangi Lal Sharma at 11/28/2012 05:00:00 pm No comments: Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: OS Lab Older Posts Home Subscribe to: Posts (Atom) Labels DSA Lab (20) C vital lab (16) OS Lab (12) DAA Lab (7) Graphics Lab (5) C++ vital lab (4) Attention (3) Compiler Lab (3) FORUM (1) Problems (1) Welcome (1) Feedjit Feedjit Live Blog Stats About Me Mangi Lal Sharma View my well-constructed profile My other blogs mangilalsaraswat.blogspot.com Total Pageviews Get My Help To Write Your Program mangilalsharma Fiverr Seller Main Skills: WordPress, C, C++, Java, PHP. I have wits in WordPress 5 years, C 8 years, C++ 7 years, Java 5 years and PHP 5 years. My services contains everything related to websites and desktop software. Blog Archive ▼  2015 (3) ▼  September (3) Factset Question: Subarray of k Size from aVariety... C program for User specified Custom atoi Function Co... C Program to Demonstrate use of atoi Function ►  2014 (3) ►  November (3) ►  2013 (9) ►  July (1) ►  June (6) ►  April (1) ►  March (1) ►  2012 (50) ►  December (3) ►  November (47) Flagcounter Copyright by world-of-c-programming.blogspot.com. Simple theme. Powered by Blogger.