title: operating systems memory management paging scheme in c
body: <p><strong><em>I'm working on operating system <code>Memory Management Paging Scheme</code> Simulation in <code>C</code>,So Here is what i've done so far:</em></strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdlib.h&gt;
  void main()
  {
    int alloc[50], base[50], frame[50], job[50];
    int i, n, pa, fs, ps, nf, temp;
  
  clrscr();
      printf("\n\t\t PAGING\n");
  
      printf("\n\t Enter the physical address space:");
          scanf("%d",&amp;pa);
      printf("\n\t Enter the page size:");
          scanf("%d",&amp;ps);
  
      nf=pa/ps;
      printf("\n\t Number of frames = %d",nf);
      for(i=0;i&lt;nf;i++)
      {
          alloc[i]=0;
          printf("Enter job number %d",i+1);
              scanf("%d",job[i]);
          if (  // If job can fit  ) {
       // Here job will fit one by one
              temp=rand()%nf;
              while( alloc[temp] == 1 )
                  temp=rand()%nf;
              alloc[temp]=1;
              frame[i]=temp;
       // The main algo will come here
              base[i]=frame[i]*ps;
              printf("\n %d\t\t %d\t\t %d\t\t",i,frame[i],base[i]);
  
          } else {
      //If the job can not fit in the memory
              printf("Job %d Can't fit in the Memory.\n",i+1);
              break;
          }
  
      }
  getch();
  }
  </code></pre>
  
  <p><strong>I just want to implement the below program to what i require;</strong></p>
  
  <p>1.<em>First when I enter physical address and page size according to the page number I can enter my jobs</em></p>
  
  <p>2.<em>Second Each job can fit in the number of pages according to the job size</em></p>
  
  <p>3.<em>Third Each time I enter job the <code>Memory Block Table (MBT)</code> should reload and tells how much memory available or occupied</em> </p>
  
  <p>4.<em>and Finally if there is not enough space to put the larger job it gives Error</em></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdlib.h&gt;
  void main()
  {
    int ps,np,nf,log;
    int alloc[50],base[50],frame[50],page[50];
    int i,f,n,pa,fs,pno,add,offset;
    int temp;
    int f1;
  clrscr();
      printf("\n\t\t PAGING\n");
      printf("\n\t Enter the logical address space:");
          scanf("%d",&amp;log);
      printf("\n\t Enter the page size:");
          scanf("%d",&amp;ps);
      printf("\n\t Enter the physical address space:");
          scanf("%d",&amp;pa);
      fs=ps;
      np=log/ps;
      nf=pa/fs;
      printf("\n\t Number of pages  = %d",np);
      printf("\n\t Number of frames = %d",nf);
      for(i=0;i&lt;nf;i++)
          alloc[i]=0;
      for(i=0;i&lt;np;i++)
      {
          temp=rand()%nf;
          while(alloc[temp]==1)
              temp=rand()%nf;
          alloc[temp]=1;
          frame[i]=temp;
      }
      printf("\n Page No \t Frame No \t Base address ");
          for(i=0;i&lt;np;i++)
          {
              base[i]=frame[i]*ps;
              page[i]=i;
              printf("\n%d\t\t %d\t %d\t\t",i,frame[i],base[i]);
          }
  getch();
  }
  </code></pre>