Search
 
SCRIPT & CODE EXAMPLE
 

C

. Simulate MVT and MFT.

// AIM: A Program to simulate the MFT

/*
ALGORITHM:

	Step1: Start the process.
	Step2: Declarevariables.
	Step3: Enter total memory size ms.

	Step4: Allocate memory for os.
             Ms=ms-os
	Step5: Read the no partition to be divided n Partition size=ms/n.
	Step6: Read the process no and process size.
	Step 7: If process size is less than partition size allot alse blocke the process. While allocating update memory wastage-external fragmentation.

			if(pn[i]==pn[j])
				f=1;
			if(f==0)
	        {
				if(ps[i]<=siz)
				{
					extft=extft+size-ps[i];
					avail[i]=1;
					count++;
				}
			}
        
	Step 8: Print the results
	Step 9 :Stop.
*/

// PROGRAM:

#include<stdio.h>

int main()
{
	int m,p,s,p1;
	int m1[4],i,f,f1=0,f2=0,fra1,fra2,s1,pos;
	printf("Enter the memory size:");
	scanf("%d",&m);
	printf("Enter the no of partitions:");
	scanf("%d",&p);
	s=m/p;
	printf("Each partn size is:%d",s);
	printf("
Enter the no of processes:");
	scanf("%d",&p1);
	pos=m;
	for(i=0;i<p1;i++)
	{
		if(pos<s)
		{
			printf("
There is no further memory for process%d",i+1);
			m1[i]=0;
			break;
		}
		else
		{
			printf("
Enter the memory req for process%d:",i+1);
			scanf("%d",&m1[i]);
			if(m1[i]<=s)
			{
				printf("
Process is allocated in partition%d",i+1);
				fra1=s-m1[i];
				printf("
Internal fragmentation for process is:%d",fra1);
				f1=f1+fra1;
				pos=pos-s;
			}
			else
			{
				printf("
Process not allocated in partition%d",i+1);
				s1=m1[i];
				while(s1>s)
				{
					s1=s1-s;
					pos=pos-s;
				}
				pos=pos-s;
				fra2=s-s1;
				f2=f2+fra2;
				printf("
External Fragmentation for this process is:%d",fra2);
			}
		}
	}
	printf("
Process	allocatedmemory");
	for(i=0;i<p1;i++)
		printf("
%5d	%5d",i+1,m1[i]);
	f=f1+f2;
	printf("
The tot no of fragmentation is:%d",f);
	return 0;
}

/*
INPUT/OUTPUT:

Enter the memory size: 80
Enter the no of partitions: 4
Each partition size: 20
Enter the number of processes: 2
Enter the memory req for process1: 18
Process1 is allocated in partn1
Internal fragmentation for process1 is: 2
Enter the memory req for process2: 22
Process2 is not allocated in partn2
External fragmentation for process2 is: 18
*/
Comment

PREVIOUS NEXT
Code Example
C :: create point cloud from rgbd image in open3d v0.10 
C :: implement crc using c language 
C :: declaration in c 
C :: sizeof file c 
C :: c memcpy array 
C :: arduino empty serial buffer 
C :: getline() in c 
C :: check if string contains a character in c 
C :: string in c and how it works 
C :: array of strings c 
C :: What should main() return in C? 
C :: commenting in c 
C :: english to russian translation 
C :: C Syntax of goto Statement 
C :: what does packing mean in c 
C :: C Syntax of return statement 
C :: Command to compile and execute a c file program consecutively 
C :: https://www.tiktok.com/@kaiwan.99/video/7115521325766069510?is_from_webapp=1&sender_device=pc&web_id=7083069815002449410 
C :: resto de division recursiva 
C :: C - Type Casting 
C :: ejemplo c holamundo 
C :: overhead computer science 
C :: man write c 
C :: transform yt video into background overlay 
C :: how to import c data type 
C :: how to know a type of a numbe in c 
C :: String insertion into another string 
C :: exponent calculator 
C :: pygraphviz show 
C :: sort linked list c 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =