OS Programs Remaining
OS Programs Remaining
Output:
Memory Management Scheme - First Fit
Enter the number of blocks:3
Enter the number of files:2
Best Fit:
#include<stdio.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];
printf("\n\tMemory Management Scheme – Best 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)
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\tFragment");
for(i=1;i<=nf && ff[i]!=0;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]);
}
Output:
Worst Fit:
#include <stdio.h>
}
}
// Driver code
int main()
{
int blockSize[20], processSize[20], blocks, processes, i, j;
printf("\nEnter the number of blocks:");
scanf("%d",&blocks);
printf("Enter the number of files:");
scanf("%d",&processes);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=blocks;i++)
{
printf("Block %d:",i);
scanf("%d",&blockSize[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=processes;i++)
{
printf("File %d:",i);
scanf("%d",&processSize[i]);
}
implimentWorstFit(blockSize, blocks, processSize, processes);
return 0;
}
Output:
Enter the size of the blocks:-
Block 1:5
Block 2:2
Block 3:7
Enter the size of the files :-
File 1:1
File 2:4
int main() {
int frames, pages[100], temp[100];
int totalPages, i, j, k, pageFaults = 0, pos = 0, flag;
printf("\nPage\tFrames\n");
for (i = 0; i < totalPages; i++) {
flag = 0;
Page Frames
2 2--
3 23-
2 Hit
1 231
5 531
2 521
4 524
5 Hit
2 Hit
3 324
2 Hit
#define MAX_FRAMES 10
#define MAX_PAGES 100
int main() {
int frames[MAX_FRAMES], pages[MAX_PAGES], time[MAX_FRAMES];
int total_pages, total_frames, count = 0, faults = 0;
int i, j, flag1, flag2, pos;
return 0;
}
Output:
Enter number of frames: 3
Enter number of pages: 11
Enter the page reference string:
23215245232
Frames: 2 - -
Frames: 2 3 -
Frames: 2 3 -
Frames: 2 3 1
Frames: 2 5 1
Frames: 2 5 1
Frames: 2 5 4
Frames: 2 5 4
Frames: 2 5 4
Frames: 2 5 3
Frames: 2 5 3
c) LFU
#include <stdio.h>
#include <limits.h>
#define MAX_FRAMES 10
#define MAX_PAGES 100
int main() {
int pages[MAX_PAGES], n, framesCount;
Frame frames[MAX_FRAMES];
int time = 0, faults = 0;
// Input
printf("Enter number of pages: ");
scanf("%d", &n);
printf("Enter the page reference string: ");
for (int i = 0; i < n; i++) {
scanf("%d", &pages[i]);
}
printf("Enter number of frames: ");
scanf("%d", &framesCount);
// Initialize frames
for (int i = 0; i < framesCount; i++) {
frames[i].page = -1;
frames[i].frequency = 0;
frames[i].time = 0;
}
// LFU logic
for (int i = 0; i < n; i++) {
int currentPage = pages[i];
int found = 0;
nop = ms/ps;
printf("\nThe no. of pages available in memory are -- %d ",nop);
if(s[i] >rempages)
{
printf("\nMemory is Full");
break;
}
rempages = rempages - s[i];
else
{
pa=fno[x][y]*ps+offset;
printf("\nThe Physical Address is -- %d",pa);
}
}
Output:
Enter the memory size -- 1000
Enter the page size -- 100
The no. of pages available in memory are -- 10
Enter number of processes -- 3
Enter no. of pages required for p[1]-- 4