OS-Lab-Manual Edit
OS-Lab-Manual Edit
JAIPUR
Lab Objectives/Aims
Upon successful completion of this lab the student will be able to:
fragmentation
1
JECRC UNIVERSITY
JAIPUR
List of Experiments
2
10 To implement the memory management policy-segmentation. 45
11 Write a C Program to implement Sequential File Allocation
51
method.
12 Write a C Program to implement Indexed File Allocation
54
method.
13 Write a C Program to implement Linked File Allocation method. 57
14 Write a program to implement multi program variable task
60
(MVT).
15 Write a program to implement multi program fixed task (MFT). 62
Aim: Write a C program to implement the various process scheduling mechanisms such as FCFS
scheduling:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Set the waiting of the first process as ‘0’ and its burst time as its turnaround time
(a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
(b) Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
3
/* PROGRAM */
#include<stdio.h>
void main()
int i,n,sum,wt,tat,twt,ttat;
int t[10];
float awt,atat;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("\n %d",&t[i]);
sum=0;
twt=0;
ttat=t[0];
for(i=1;i<n;i++)
sum+=t[i-1];
wt=sum;
tat=sum+t[i];
4
twt=twt+wt;
ttat=ttat+tat;
printf("\n\n");
awt=(float)twt/n;
atat=(float)ttat/n;
getch();
OUTPUT:
1 0 2
2 2 7
3 7 11
5
Exp No: 2 Date: _ _/_ _/ _ _
Aim: Write a C program to implement the various process scheduling mechanisms such as SJF
Scheduling.
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to highest
burst time.
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst time.
(c) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
(d) Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
6
/* PROGRAM */
#include<stdio.h>
void main()
int i,j,k,n,sum,wt[10],tt[10],twt,ttat;
int t[10],p[10];
float awt,atat;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("\n %d",&t[i]);
for(i=0;i<n;i++)
p[i]=i;
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(t[i]>t[k])
int temp;
temp=t[i];
t[i]=t[k];
7
t[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
} }
wt[0]=0;
for(i=0;i<n;i++)
sum=0;
for(k=0;k<i;k++)
wt[i]=sum+t[k];
sum=wt[i];
} }
for(i=0;i<n;i++)
tt[i]=t[i]+wt[i];
for(i=0;i<n;i++)
twt=0;
ttat=t[0];
8
for(i=1;i<n;i++)
twt=twt+wt[i];
ttat=ttat+tt[i];
awt=(float)twt/n;
atat=(float)ttat/n;
getch();
}}
OUTPUT:
1 3 0 3
0 4 3 7
2 5 7 12
9
Exp No: 3 Date: _ _/_ _/
Aim: Write a C program to implement the various process scheduling mechanisms such as Round Robin
Scheduling.
Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
(a) Waiting time for process(n) = waiting time of process(n-1)+ burst time of process(n-1 ) + the
time difference in getting the CPU from process(n-1)
(b) Turn around time for process(n) = waiting time of process(n) + burst time of process(n)+ the
time difference in getting CPU from process(n).
Step 7: Calculate
/* PROGRAM */
10
#include<stdio.h>
#include<conio.h>
void main()
int ts,pid[10],need[10],wt[10],tat[10],i,j,n,n1;
int bt[10],flag[10],ttat=0,twt=0;
float awt,atat;
clrscr();
scanf("%d",&n);
n1=n;
scanf("%d",&ts);
for(i=1;i<=n;i++)
scanf("%d",&pid[i]);
scanf("%d",&bt[i]);
need[i]=bt[i];
for(i=1;i<=n;i++)
flag[i]=1;
wt[i]=0;
11
}
while(n!=0)
for(i=1;i<=n;i++)
if(need[i]>=ts)
for(j=1;j<=n;j++)
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
wt[j]+=ts;
need[i]-=ts;
if(need[i]==0)
flag[i]=0;
n--;
} }
else
for(j=1;j<=n;j++)
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
wt[j]+=need[i];
need[i]=0;
12
n--;
flag[i]=0;
}}}
for(i=1;i<=n1;i++)
tat[i]=wt[i]+bt[i];
twt=twt+wt[i];
ttat=ttat+tat[i];
awt=(float)twt/n1;
atat=(float)ttat/n1;
for(i=1;i<=n1;i++)
printf("\n %5d \t %5d \t\t %5d \t\t %5d \t\t %5d \n", i,pid[i],bt[i],wt[i],tat[i]);
getch();
OUTPUT:
13
5
1 5 10 15 25
2 6 15 25 40
3 7 20 25 45
4 8 25 20 45
14
Exp No: 4 Date: _ _/_ _/
Aim: Write a C program to implement the various process scheduling mechanisms such as Priority
Scheduling.
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 5: Set the waiting of the first process as ‘0’ and its burst time as its turnaround time
(e) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
(f) Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 7: Calculate
/* PROGRAM */
#include <stdio.h>
#include <conio.h>
void main()
int i,j,n,tat[10],wt[10],bt[10],pid[10],pr[10],t,twt=0,ttat=0;
float awt,atat;
clrscr();
15
printf("\n-----------PRIORITY SCHEDULING--------------\n");
scanf("%d", &n);
for (i=0;i<n;i++)
pid[i] = i;
scanf("%d",&bt[i]);
scanf ("%d",&pr[i]);
// Sorting start
for (i=0;i<n;i++)
for(j=i+1;j<n;j++)
t = pr[i];
pr[i] = pr[j];
pr[j] = t;
t = bt[i];
bt[i] = bt[j];
bt[j] = t;
t = pid[i];
pid[i] = pid[j];
pid[j] = t;
16
} }
// Sorting finished
tat[0] = bt[0];
wt[0] = 0;
for (i=1;i<n;i++)
printf("\n---------------------------------------------------------------\n");
printf("\n--------------------------------------------------------------\n");
for(i=0;i<n;i++)
printf("\n%d\t\t%d\t%d\t\t%d\t\t%d",pid[i],pr[i],bt[i],wt[i],tat[i]);
for(i=0;i<n;i++)
ttat = ttat+tat[i];
awt = (float)twt / n;
atat = (float)ttat / n;
getch();
17
OUTPUT:
-----------PRIORITY SCHEDULING--------------
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
2 1 4 0 4
1 2 6 4 10
0 3 2 10 12
3 7 5 12 17
AIM: To implement deadlock avoidance & Prevention by using Banker’s Algorithm Deadlock
avoidance & Dead Lock Prevention
18
/* BANKER’S ALGORITHM */
When a new process enters a system, it must declare the maximum number of instances of each resource
type it needed. This number may exceed the total number of resources in the system. When the user
request a set of resources, the system must determine whether the allocation of each resources will leave
the system in safe state. If it will the resources are allocation; otherwise the process must wait until some
other process release the resources.
Data structures
n-Number of process, m-number of resource types.
Available: Available[j]=k, k – instance of resource type Rj is available.
Max: If max[i, j]=k, Pi may request at most k instances resource Rj.
Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource Rj
Need: If Need[I, j]=k, Pi may need k more instances of resource type Rj, Need[I, j]=Max[I, j]-
Allocation[I, j];
Safety Algorithm
1. Work and Finish be the vector of length m and n respectively, Work=Available and Finish[i]
=False.
2. Find an i such that both
Finish[i] =False
Need<=Work
If no such I exists go to step 4.
Let Request i be request vector for the process Pi, If request i=[j]=k, then process Pi wants k instances of
resource type Rj.
Allocation I =Allocation+Request I;
If the resulting resource allocation state is safe, the transaction is completed and process Pi is allocated
its resources. However if the state is unsafe, the Pi must wait for Request i and the old resource-
allocation state is restored.
ALGORITHM:
19
1. Start the program.
2. Get the values of resources and processes.
3. Get the avail value.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safe state.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. or not if we allow the request.
10. stop the program.
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
struct da
int max[10],a1[10],need[10],before[10],after[10];
}p[10];
void main()
int i,j,k,l,r,n,tot[10],av[10],cn=0,cz=0,temp=0,c=0;
clrscr();
scanf("%d",&n);
scanf("%d",&r);
for(i=0;i<n;i++)
printf("PROCESS %d \n",i+1);
for(j=0;j<r;j++)
20
scanf("%d",&p[i].max[j]);
for(j=0;j<r;j++)
scanf("%d",&p[i].a1[j]);
p[i].need[j]=p[i].max[j]-p[i].a1[j];
}}
for(i=0;i<r;i++)
scanf("%d",&tot[i]);
for(i=0;i<r;i++)
for(j=0;j<n;j++)
temp=temp+p[j].a1[i];
av[i]=tot[i]-temp;
temp=0;
for(i=0;i<n;i++)
for(j=0;j<r;j++)
printf("%d",p[i].max[j]);
21
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].a1[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].need[j]);
printf("\t");
for(j=0;j<r;j++)
if(i==0)
printf("%d",tot[j]);
printf(" ");
for(j=0;j<r;j++)
if(i==0)
printf("%d",av[j]);
}}
for(l=0;l<n;l++)
for(i=0;i<n;i++)
for(j=0;j<r;j++)
if(p[i].need[j] >av[j])
22
cn++;
if(p[i].max[j]==0)
cz++;
for(j=0;j<r;j++)
p[i].before[j]=av[j]-p[i].need[j];
p[i].after[j]=p[i].before[j]+p[i].max[j];
av[j]=p[i].after[j];
p[i].max[j]=0;
printf("\n P %d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].before[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].after[j]);
cn=0;
cz=0;
c++;
break;
else
23
cn=0;cz=0;
}}}
if(c==n)
else
getch();
OUTPUT:
//TEST CASE 1:
PROCESS 1
PROCESS 2
24
PROCESS 3
PROCESS 4
P2 010 623
P1 401 723
P3 620 934
25
P4 514 936
//TEST CASE:2
PROCESS 1
PROCESS 2
PROCESS 3
26
PROCESS 4
DEADLOCK OCCURED
JECRC UNIVERSITY
JAIPUR
Step 2: When the page is required replace the page at the head of the queue
27
Step 3: Now the new page is inserted at the tail of the queue
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
void main()
clrscr();
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf("\n");
for(i=0;i<nor;i++)
flag=0;
28
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
flag=1;
break;
}}
if(flag==0)
pf++;
victim++;
victim=victim%nof;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}}
getch(); }
OUTPUT:
564123
29
...................................... 5 6 4 1 2 3
Reference np5-> 5 -1 -1 -1
Reference np6-> 5 6 -1 -1
Reference np4-> 5 6 4 -1
Reference np1-> 5 6 4 1
Reference np2-> 2 6 4 1
Reference np3-> 2 3 4 1
JECRC UNIVERSITY
JAIPUR
Here we select the page that has not been used for the longest period of time.
Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
30
Step 4: Create a stack
Step 5: When the page fault occurs replace page present at the bottom of the stack
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],lrucal[50],count=0;
int lruvictim();
void main()
clrscr();
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("\n………………………………..");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
31
{
frm[i]=-1;
lrucal[i]=0;
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
flag=0;
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
flag=1;
break;
} }
if(flag==0)
count++;
if(count<=nof)
victim++;
else
victim=lruvictim();
pf++;
32
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
recent[ref[i]]=i;
getch(); }
int lruvictim()
int i,j,temp1,temp2;
for(i=0;i<nof;i++)
temp1=frm[i];
lrucal[i]=recent[temp1]; }
temp2=lrucal[0];
for(j=1;j<nof;j++)
if(temp2>lrucal[j])
temp2=lrucal[j];
for(i=0;i<nof;i++)
if(ref[temp2]==frm[i])
return i;
return 0; }
OUTPUT:
33
LRU PAGE REPLACEMENT ALGORITHM
654231
…………………. 6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference NO 5-> 6 5 -1
Reference NO 4-> 6 5 4
Reference NO 2-> 2 5 4
Reference NO 3-> 2 3 4
Reference NO 1-> 2 3 1
AIM: To implement page replacement algorithms Optimal (The page which is not used for longest
time)
Here we select the page that will not be used for the longest period of time.
Step 2: When the page fault occurs replace page that will not be used for the longest period of time
/* PROGRAM */
#include<stdio.h>
34
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],optcal[50],count=0;
int optvictim();
void main()
clrscr();
printf("\n.................................");
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
clrscr();
printf("\n................................");
printf("\n....................\n");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=0;i<nof;i++)
{ frm[i]=-1;
optcal[i]=0; }
35
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
flag=0;
printf("\n\tref no %d ->\t",ref[i]);
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
{ flag=1;
break;
} }
if(flag==0)
count++;
if(count<=nof)
victim++;
else
victim=optvictim(i);
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
} }
36
getch(); }
int i,j,temp,notfound;
for(i=0;i<nof;i++)
notfound=1;
for(j=index;j<nor;j++)
if(frm[i]==ref[j])
notfound=0;
optcal[i]=j;
break;
if(notfound==1)
return i;
temp=optcal[0];
for(i=1;i<nof;i++)
if(temp<optcal[i])
temp=optcal[i];
for(i=0;i<nof;i++)
if(frm[temp]==frm[i])
return i;
return 0; }
OUTPUT:
37
OPTIMAL PAGE REPLACEMENT ALGORITHM
654231
…………………. 6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference NO 5-> 6 5 -1
Reference NO 4-> 6 5 4
Reference NO 2-> 2 5 4
Reference NO 3-> 2 3 4
Reference NO 1-> 2 3 1
38
Step 6: Stop the process.
/* PROGRAM */
#include <stdio.h>
#include <conio.h>
struct pstruct
int fno;
int pbit;
}ptable[10];
int pmsize,lmsize,psize,frame,page,ftable[20],frameno;
void info()
scanf("%d",&pmsize);
scanf("%d",&lmsize);
scanf("%d",&psize);
void assign()
39
int i;
for (i=0;i<page;i++)
ptable[i].fno = -1;
ptable[i].pbit= -1;
for(i=0; i<frame;i++)
ftable[i] = 32555;
for (i=0;i<page;i++)
scanf("%d",&frameno);
ftable[frameno] = i;
if(ptable[i].pbit == -1)
ptable[i].fno = frameno;
ptable[i].pbit = 1;
} }
getch();
// clrscr();
printf("\n\nPAGE TABLE\n\n");
for (i=0;i<page;i++)
printf("%d\t\t%d\t\t%d\n",i,ptable[i].fno,ptable[i].pbit);
printf("\n\n\n\tFRAME TABLE\n\n");
printf("FrameAddress PageNo\n\n");
40
for(i=0;i<frame;i++)
printf("%d\t\t%d\n",i,ftable[i]);
void cphyaddr()
int laddr,paddr,disp,phyaddr,baddr;
getch();
// clrscr();
scanf("%d",&baddr);
scanf("%d",&laddr);
if(ptable[paddr].pbit == 1 )
void main()
clrscr();
info();
assign();
cphyaddr();
41
getch();
OUTPUT:
PAGE TABLE
0 5 1
1 6 1
2 7 1
3 2 1
FRAME TABLE
0 32555
1 32555
2 3
3 32555
42
4 32555
5 0
6 1
7 2
Step 3: get the base address and length for each segment.
Step 5: check whether the segment number is within the limit, if not display the error message.
Step 6: Check whether the byte reference is within the limit, if not display the error message.
43
Step 7: Calculate the physical memory and display it.
/* PROGRAM */
#include <stdio.h>
#include <conio.h>
#include <math.h>
int sost;
void gstinfo();
void ptladdr();
struct segtab
int sno;
int baddr;
int limit;
int val[10];
}st[10];
void gstinfo()
int i,j;
scanf("%d",&sost);
for(i=1;i<=sost;i++)
st[i].sno = i;
44
scanf("%d",&st[i].baddr);
scanf("%d",&st[i].limit);
for(j=0;j<st[i].limit;j++)
scanf("%d",&st[i].val[j]);
void ptladdr()
int i,swd,d=0,n,s,disp,paddr;
clrscr();
for(i=1;i<=sost;i++)
printf("\t\t%d \t\t%d\t\t%d\n\n",st[i].sno,st[i].baddr,st[i].limit);
scanf("%d",&swd);
n=swd;
while (n != 0)
n=n/10;
d++;
45
s = swd/pow(10,d-1);
disp = swd%(int)pow(10,d-1);
if(s<=sost)
else
else
void main()
char ch;
clrscr();
gstinfo();
do
ptladdr();
46
flushall();
scanf("%c",&ch);
getch();
OUTPUT:
47
Enter the 4 address Value: 41
SEGMENT TABLE
1 4 5
2 5 4
3 3 4
Do U want to Continue(Y/N)
SEGMENT TABLE
1 4 5
2 5 4
3 3 4
Do U want to Continue(Y/N)
48
Exp No: 11 Date: _ _/_ _/
Step 3: Get the number of processes and values of block size for each process.
Step 4: First fit algorithm searches the entire entire memory block until a hole which is big enough is
encountered. It allocates that memory block for the requesting process.
Step 5: Best-fit algorithm searches the memory blocks for the smallest hole which can be allocated to
requesting process and allocates if.
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and allocates it to the
process.
Step 7: Analyses all the three memory management techniques and display the best algorithm which
utilizes the memory resources effectively and efficiently.
49
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
main()
int n,i,j,b[20],sb[20],t[20],x,c[20][20];
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
scanf("%d",&sb[i]);
t[i]=sb[i];
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
printf("Filename\tStart block\tlength\n");
for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1,t[i],b[i]);
scanf("%d",&x);
printf("length is:%d",b[x-1]);
50
printf("blocks occupied:");
for(i=0;i<b[x-1];i++)
printf("%4d",c[x-1][i]);
getch();
OUTPUT:
1 2 4
2 5 10
51
Exp No: 12 Date: _ _/_ _/
Step 1: Start.
Step 7: Check there is any cosumer. If yes check whether the buffer is empty
Step 10: Repeat checking for the producer and consumer till required
/* PROGRAM */
52
#include<stdio.h>
#include<conio.h>
main()
int n,m[20],i,j,sb[20],s[20],b[20][20],x;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d%d",&sb[i],&s[i]);
scanf("%d",&m[i]);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
} printf("\nFile\t index\tlength\n");
for(i=0;i<n;i++)
printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
scanf("%d",&x);
53
printf("file name is:%d\n",x);
i=x-1;
printf("Index is:%d",sb[i]);
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
getch();
OUTPUT:
2 5 4 6 7 2 6 4 7
1 2 10
2 3 5
54
Exp No: 13 Date: _ _/_ _/
Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
Step 5: When the page fault occurs replace page present at the bottom of the stack
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
struct file
char fname[10];
int start,size,block[10];
}f[10];
main()
int i,j,n;
clrscr();
55
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s",&f[i].fname);
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
scanf("%d",&f[i].size);
for(j=1;j<=f[i].size;j++)
scanf("%d",&f[i].block[j]);
printf("File\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);
for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);
printf("\n");
getch();
56
}
OUTPUT:
12
15
45
32
25
rajat 20 6 4--->12--->15--->45--->32--->25
jit 12 5 6--->5--->4--->3--->2
57
Exp No: 14 Date: _ _/_ _/ _
/* MVT ALGORITHM */
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
main()
int i,m,n,tot,s[20];
clrscr();
scanf("%d",&tot);
scanf("%d",&n);
scanf("%d",&m);
58
for(i=0;i<n;i++)
scanf("%d",&s[i]); }
tot=tot-m;
for(i=0;i<n;i++)
if(tot>=s[i])
tot=tot-s[i];
else
getch(); }
OUTPUT:
External Fragmentation is = 2
59
Exp No: 15 Date: _ _/_ _/
/* MFT ALGORITHM */
/* PROGRAM */
#include<stdio.h>
#include<conio.h>
main()
int ms,i,ps[20],n,size,p[20],s,intr=0;
clrscr();
scanf("%d",&ms);
scanf("%d",&s);
ms-=s;
scanf("%d",&n);
size=ms/n;
60
for(i=0;i<n;i++)
scanf("%d%d",&p[i],&ps[i]);
if(ps[i]<=size)
intr=intr+size-ps[i];
printf("process%d is allocated\n",p[i]);
else
printf("process%d is blocked",p[i]);
getch(); }
OUTPUT:
Internal Fragmentation is = 4
61