Multi-programming with fixed number of tasks(MFT) program in C
Program:
#include<stdio.h>
int main()
{
int tm,om,n,i,block_size,internal_frag;
printf("Enter total memory size,memory for OS and # of processes:\n");
scanf("%d%d%d",&tm,&om,&n);
int process[n];
tm = tm - om;
block_size = tm / n;
for (i = 0; i < n; ++i)
{
printf("Enter process %d size :\n",i+1);
scanf("%d",&process[i]);
if(process[i] <= block_size){
internal_frag = internal_frag + block_size - process[i];
printf("Allocated memory to process :%d\n",i+1);
}else{
printf("Process %d is blocked\n",i+1);
}
}
printf("Fragmentation is %d.\n",internal_frag);
return 0;
}
Output:
Enter total memory size,memory for OS and # of processes:
50
10
4
Enter process 1 size :
Allocated memory to process :1
Enter process 2 size :
Allocated memory to process :2
Enter process 3 size :
Allocated memory to process :3
Enter process 4 size :
Allocated memory to process :4
Fragmentation is 7.
#include<stdio.h>
int main()
{
int tm,om,n,i,block_size,internal_frag;
printf("Enter total memory size,memory for OS and # of processes:\n");
scanf("%d%d%d",&tm,&om,&n);
int process[n];
tm = tm - om;
block_size = tm / n;
for (i = 0; i < n; ++i)
{
printf("Enter process %d size :\n",i+1);
scanf("%d",&process[i]);
if(process[i] <= block_size){
internal_frag = internal_frag + block_size - process[i];
printf("Allocated memory to process :%d\n",i+1);
}else{
printf("Process %d is blocked\n",i+1);
}
}
printf("Fragmentation is %d.\n",internal_frag);
return 0;
}
Output:
Enter total memory size,memory for OS and # of processes:
50
10
4
Enter process 1 size :
Allocated memory to process :1
Enter process 2 size :
Allocated memory to process :2
Enter process 3 size :
Allocated memory to process :3
Enter process 4 size :
Allocated memory to process :4
Fragmentation is 7.
Comments
Post a Comment