Skip to main content

MFT and MVT

MFT Multiprogramming with finite no of tasks

#include<stdio.h>
#include<conio.h>
main()
{
 int ms, bs, nob, ef,n, mp[10],tif=0;
 int i,p=0;
 clrscr();
 printf("Enter the total memory available (in Bytes) -- ");
 scanf("%d",&ms);
 printf("Enter the block size (in Bytes) -- ");
 scanf("%d", &bs);
 nob=ms/bs;
 ef=ms - nob*bs;
 printf("\nEnter the number of processes -- ");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
printf("Enter memory required for process %d (in Bytes)-- ",i+1);
scanf("%d",&mp[i]);
 }
 printf("\nNo. of Blocks available in memory -- %d",nob);
 printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION");
 for(i=0;i<n && p<nob;i++)
 {
printf("\n %d\t\t%d",i+1,mp[i]);
if(mp[i] > bs)
printf("\t\tNO\t\t---");
else
{
printf("\t\tYES\t%d",bs-mp[i]);
tif = tif + bs-mp[i];
p++;
}
 }
 if(i<n)
printf("\nMemory is Full, Remaining Processes cannot be accomodated");
 printf("\n\nTotal Internal Fragmentation is %d",tif);
 printf("\nTotal External Fragmentation is %d",ef);
}

MVT  multiprogramming with variable no of tasks

#include<stdio.h>
#include<conio.h>
int main()
{
int m,p,s,p1;
int m1[4],i,f,f1=0,f2=0,fra1,fra2,s1,pos;
clrscr();
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("\nEnter the no of processes:");
scanf("%d",&p1);
pos=m;
for(i=0;i<p1;i++)
{
if(pos<s)
{
printf("\nThere is no further memory for process%d",i+1);
m1[i]=0;
break;
}
else
{
printf("\nEnter the memory req for process%d:",i+1);
scanf("%d",&m1[i]);
if(m1[i]<=s)
{
printf("\nProcess is allocated in partition%d",i+1);
fra1=s-m1[i];
printf("\nInternal fragmentation for process is:%d",fra1);
f1=f1+fra1;
pos=pos-s;
}
else
{
printf("\nProcess 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("\nExternal Fragmentation for this process is:%d",fra2);
}
}
}
printf("\nProcess\tallocatedmemory");
for(i=0;i<p1;i++)
printf("\n%5d\t%5d",i+1,m1[i]);
f=f1+f2;
printf("\nThe tot no of fragmentation is:%d",f);
}

Comments

Popular posts from this blog

Bit Stuffing Program

#include<stdio.h> main() { int i,j,k,n,count=0; int a[30],b[30]; printf("The flag is 01111110"); printf("\n Enter the message size:"); scanf("%d",&n); printf("\n Enter the message in bits(0/1):"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\n The message is:"); for(i=0;i<n;i++) { printf("%d",a[i]); } printf("\n"); for(i=0,j=0;i<n;i++,j++) { if(a[i]==1) { if(count==5) { b[j]=0; j++; count=0; } else count++; b[j]=a[i]; } k=j; printf("\n The coded message is:"); printf("01111110 /t"); for(j=0;j<k;j++) { printf("%d",b[j]); } printf("\01111110\n"); count=0; printf("The encoded message is :\n"); printf("\n 01111110 \t"); for(i=0;i<k;i++) { if(b[i]==1 && count<5) { printf("%d",b[i]...

CPU Schedueling programs

        Fcfs program         #include<stdio.h> #include<conio.h> main() { int bt[20], wt[20], tat[20], i, n; float wtavg, tatavg; printf("\nEnter the number of processes -- "); scanf("%d", &n); for(i=0;i<n;i++) { printf("\nEnter Burst Time for Process %d -- ", i); scanf("%d", &bt[i]); } wt[0] = wtavg = 0; tat[0] = tatavg = bt[0]; for(i=1;i<n;i++) { wt[i] = wt[i-1] +bt[i-1]; tat[i] = tat[i-1] +bt[i]; wtavg = wtavg + wt[i]; tatavg = tatavg + tat[i]; } printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n"); for(i=0;i<n;i++) printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]); printf("\nAverage Waiting Time -- %f", wtavg/n); printf("\nAverage Turnaround Time -- %f", tatavg/n); getch(); } Output SJF program #include<stdio.h> #include<conio.h> main() { int p[20], bt[20], wt[20],...