Home > C++, Sistem Operasi > Source Code Sistem Paging LRU Dalam C++

Source Code Sistem Paging LRU Dalam C++

Source code dibawah menerapkan konsep sistem paging LRU (Least Recently Used) dengan menggunakan C++. Kalau yang sistem paging FIFO lihat disini.

 #include "stdio.h"
 #include "stdlib.h"
 #include "iostream.h"
 #include "conio.h"

 int b[4]={0};
 int a[100];
 int m=0,n=0;
 int i,j,x;

 Cetak()
 {
	  int i;
	  printf("  %d   |    Yes     |  ",a[j]);
	  for(i=0;i<4;i++)
	  printf("%d ",b[i]);
	  printf("\n");
	  return 0;
 }

 LRU()
 {
	  int c=0;
	  n=0;
	  printf("-----------------------------\n");
	  printf("------- Paging  LRU --------\n");
	  printf("-----------------------------\n");
	  printf(" Page | Page Fault |   Hasil \n");
	  printf("-----------------------------\n");
	  for(j=0;j<4;j++)
	 {
			b[j]=a[j];
			Cetak();
			n++;
			getch();
	  }
	  for(j=4;j<x;j++)
	 {
			m=0;
			for(i=0;i<4;i++)
				 if(a[j]==b[i])
				 {
					  c=a[j];
					  for(i++;i<4;i++)
					  {
							b[i-1]=b[i];
					  }
					  b[3]=c;
					  m=1;
					  printf("  %d   |    No      |  - \n",a[j]);
					  getch();
				 }
		  if(m==0)
			{
				for(i=0;i<3;i++)
				 b[i]=b[i+1];
				 b[3]=a[j];
				 Cetak();
				 n++;
				 getch();

			}

	  }
 printf("-----------------------------\n");
 printf("LRU page faults : %d\n",n);
 printf("Rata-rata page faults : %f\n",(double)n/15);
 printf("-----------------------------\n");
 getch();
 return 0;
 }

 main()
 {
	  clrscr();
	  printf("Input Page = ");scanf("%d", &x);

	  for(i=0;i<x;i++)
	  {
	  printf("Page ke - %d = ",i+1);scanf("%d", &a[i]);
	  }
	  printf("\n");
	  printf("Page Number : ");
	  for (i=0;i<x;i++)
	  { printf("%d ",a[i]);
	  }
	  printf("\n \n");

	  LRU();
	  getch();
	  return 0;

 }

Output program :

>>DOWNLOAD SOURCE CODE<<

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: