Program Conditions/Input : Enter the size of Processes and the size of memory
locations.
Putput conditions : A process is allocated the first memory
location which will satisfy its request.
Coding in C:
#include<stdio.h>
#include<conio.h>
#define
s 3
void
main()
{
int
p[s],m[s*2],i,j,bs,in;
clrscr();
printf("enter
the size of process");
for(i=0;i<s;i++)
{
scanf("%d",&p[i]);
}
printf("enter
the size of memory location");
for(j=0;j<s*2;j++)
{
scanf("%d",&m[j]);
}
for(i=0;i<s;i++)
{
bs=0,in=-1;
for(j=0;j<s*2;j++)
{
if(p[i]<=m[j]&&m[j]!=-1)
{
bs=m[j];
in=j;
m[in]=-1;
printf("process
%d is at location %d\n",i+1,in+1);
break;
}
}
if(bs==0)
{
printf("not
enough space");
}
}
getch();
}
OUTPUT
enter
the size of process 15
25
35
enter
the size of memory location 20
50
70
40
80
60
process
1 is at location 1
process
2 is at location 2
process
3 is at location 3