Multi-programming with variable number of tasks(MVT) program in C

Program:
#include<stdio.h>
int main()
{
int tm,om,n,i;
printf("Enter total memory size,memory for OS and # of processes:\n");
scanf("%d%d%d",&tm,&om,&n);
int process[n];
for (i = 0; i < n; ++i)
{
printf("Enter process %d size :\n",i);
scanf("%d",&process[i]);
}
tm = tm - om;
for (i = 0; i < n; ++i)
{
if(tm >= process[i]){
printf("Allocated memory to process :%d\n",i+1);
tm = tm - process[i];
}else{
printf("Process %d is blocked\n",i+1);
}
}
printf("External fragmentation is %d.\n",tm);
return 0;
}

Output:
Enter total memory size,memory for OS and # of processes:
50
10
5
Enter process 0 size :6
Enter process 1 size :6
Enter process 2 size :6
Enter process 3 size :6
Enter process 4 size :6
Allocated memory to process :1
Allocated memory to process :2
Allocated memory to process :3
Allocated memory to process :4
Allocated memory to process :5
External fragmentation is 10.




Comments

Popular posts from this blog

Multi-programming with fixed number of tasks(MFT) program in C

Linked file allocation program in C.