0% found this document useful (0 votes)
22 views14 pages

Oss

Uploaded by

ManuHiremattBS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views14 pages

Oss

Uploaded by

ManuHiremattBS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

1.

)prfifo

#include <stdio.h>

#include <stdlib.h>

int n, pref[30], fr[10];

void fifo();

int main()

int i, ch;

printf("Enter the length of the reference string : \n");

scanf("%d",&n);

printf("Enter the reference string : \n");

for (i = 0; i < n; i++)

scanf("%d",&pref[i]);

do

printf("\n\tMENU\n");

printf("\n1.FIFO\n2.exit\n enter your choice\n");

scanf("%d",&ch);

switch(ch)

case 1: fifo();

break;

case 2: break;

}while(ch!=2);

}
void fifo()

int i, f=0, r=0, s=0, count=0, flag=0, num, psize;

printf("\nEnter the size of the page frame : ");

scanf("%d",&psize);

for (i = 0; i < psize; i++)

fr[i] = -1;

while(s<n)

flag = 0;

num = pref[s];

for (i = 0; i < psize; i++)

if(num == fr[i])

s++;

flag = 1;

break;

if(flag == 0)

if(r < psize)

fr[r] = pref[s];
r++;

s++;

count++;

else

if(f >= psize)

f =0;

fr[f] = pref[s];

s++;

f++;

count++;

printf("\n");

for (i = 0; i < psize; i++)

printf("%d\t",fr[i] );

printf("\nPage Fault = %d", count);

getchar();

}
2) disk fcfs

#include<stdio.h>

#include<stdlib.h>

int n,i,cl,pl,ch,max,sum,temp,loc,min,maxl,direction;

int fcfs(int arr[n])

sum=cl-arr[0];

if(sum<0)

sum=-(sum);

for(i=1;i<n;i++)

temp=arr[i-1]-arr[i];

if(temp<0)

temp=-(temp);

sum+=temp;

for(i=0;i<n;i++)

printf("\n%d\n",arr[i]);

printf("\nTotal head movement is %d\n",sum);

return 1;

int main()

{
printf("\nEnter the total number of location:");

scanf("%d",&n);

int arr[n];

printf("\nEnter the MAX location:");

scanf("%d",&max);

printf("\nEnter current location:");

scanf("%d",&cl);

for(i=0;i<n;i++)

printf("\nEnter locations:");

scanf("%d",&arr[i]);

while(1)

printf("\nPress 1 for FCFS\n Press 2 for exit\nEnter Your Choice:");

scanf("%d",&ch);

switch(ch)

case 1:fcfs(arr);

break;

case 2:exit(0);

default:printf("\nWrong Choice");

return 1;

}
3.)sequence.c

#include "stdio.h"

#include "string.h"

#include "stdlib.h"

void seq();

int main()

int ch;

printf("\n--- File Allocation Strategies MENU ---");

printf("\n1. Sequential ");

printf("\n2 exit ");

printf("\nEnter Your Choice : ");

scanf("%d",&ch);

switch(ch)

case 1 : seq();

break;

case 2: break;

default : printf("Invalid Choice");

return 0;

void seq()

printf(" \n Sequential Allocation \n" );


struct fileTable

char name[20];

int sb, nob;

}ft[30];

int i, j, n;

char s[20];

printf("Enter no of files:");

scanf("%d",&n);

for(i=0;i<n;i++)

printf("\nEnter file name %d:",i+1);

scanf("%s",ft[i].name);

printf("Enter starting block of file %d:",i+1);

scanf("%d",&ft[i].sb);

printf("Enter no of blocks in file %d :",i+1);

scanf("%d",&ft[i].nob);

printf("\nEnter the file name to be searched -- ");

scanf("%s",s);

for(i=0 ;i<n;i++)

if(strcmp(s, ft[i].name)==0)

break;

if(i==n)

printf("\nFile Not Found");

else
{

printf("\nFILE NAME START BLOCK NO OF BLOCKS BLOCKS OCCUPIED\n");

printf("\n%s\t\t%d\t\t%d\t",ft[i].name,ft[i].sb,ft[i].nob);

for(j=0;j<ft[i].nob;j++)

printf("%d, ",ft[i].sb+j);

1)best worst.c

#include<stdio.h>

void main()

int i,j,temp,b[10],c[10],arr,n,ch,a;

printf("\t\t FIRST FIT, BEST FIT, WORST FIT\n");

printf("Enter the size of no. of blocks:");

scanf("%d",&n);

for(i=1;i<=n;i++)

printf("Enter the size of %d block:",i);

scanf("%d",&b[i]);

c[i]=b[i];

printf("\nEnter the size of Arriving block:");

scanf("%d",&arr);

printf("\n1.First fit\n2.Best fit\n3.Worst fit\nEnter your choice:");

scanf("%d",&ch);

switch(ch)
{

case 1:

for(i=1;i<=n;i++)

if(b[i]>=arr)

printf("Arriving block is allocated to %d block.",i);

break;

else

continue;

break;

case 2:

for(i=1;i<=n;i++)

for(j=1;j<n-i;j++)

if(b[i]>=b[i+1])

temp=b[i];

b[i]=b[i+1];

b[i+1]=temp;

for(i=1;i<=n;i++)

{
if(b[i]>=arr)

a=b[i];

break;

else

continue;

for(i=1;i<=n;i++)

if(c[i]==a)

printf("Arriving block is allocated to %d block.",i);

break;

case 3:

for(i=1;i<=n;i++)

for(j=1;j<n;j++)

if(b[i]>=b[i+1])

temp=b[i];

b[i]=b[i+1];

b[i+1]=temp;

}
}

for(i=1;i<=n;i++)

printf(" %d",b[i]);

break;

default:

printf("Enter the valid choice:");

Optimal.c)

#include<stdio.h>

void main()

int i,j,temp,b[10],c[10],arr,n,ch,a;

printf("\t\t FIRST FIT, BEST FIT, WORST FIT\n");

printf("Enter the size of no. of blocks:");

scanf("%d",&n);

for(i=1;i<=n;i++)

printf("Enter the size of %d block:",i);

scanf("%d",&b[i]);

c[i]=b[i];

printf("\nEnter the size of Arriving block:");

scanf("%d",&arr);

printf("\n1.First fit\n2.Best fit\n3.Worst fit\nEnter your choice:");

scanf("%d",&ch);

switch(ch)
{

case 1:

for(i=1;i<=n;i++)

if(b[i]>=arr)

printf("Arriving block is allocated to %d block.",i);

break;

else

continue;

break;

case 2:

for(i=1;i<=n;i++)

for(j=1;j<n-i;j++)

if(b[i]>=b[i+1])

temp=b[i];

b[i]=b[i+1];

b[i+1]=temp;

for(i=1;i<=n;i++)

{
if(b[i]>=arr)

a=b[i];

break;

else

continue;

for(i=1;i<=n;i++)

if(c[i]==a)

printf("Arriving block is allocated to %d block.",i);

break;

case 3:

for(i=1;i<=n;i++)

for(j=1;j<n;j++)

if(b[i]>=b[i+1])

temp=b[i];

b[i]=b[i+1];

b[i+1]=temp;

}
}

for(i=1;i<=n;i++)

printf(" %d",b[i]);

break;

default:

printf("Enter the valid choice:");

You might also like