INDEX
S.No DATE NAME OF THE PROGRAM PAGE NO SIGNATURE
1 21/7/22 Basic I/O programming
2 22/7/22 Shortest Job First Algorithm
3 29/7/22 First Come First Served Algorithm
4 05/8/22 Round Robin Scheduling Algorithm
5 06/8/22 Priority Scheduling Algorithm
6 13/8/22 Reader/Writer problem using semaphore
7 30/8/22 Banker’s algorithm for Deadlock
avoidance
8 07/9/22 First In First Out page replacement Algorithms
9 15/9/22 Least Recently Used page replacement Algorithm
10 22/9/22 First fit algorithm for memory
management
11 23/9/22 Best fit algorithm for memory
management
12 30/9/22 Worst fit algorithm for memory management
13 15/10/22 Inter-process Communication using pipes
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:1 Basic I/O programming
PROGRAM :
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
main( )
{
int fd[2];
char buf1[25]= "just a test\n";
char buf2[50];
fd[0]=open("file1",O_RDWR);
fd[1]=open("file2",O_RDWR);
write(fd[0], buf1, strlen(buf1));
printf("\n Enter the text now….");
scanf("\n %s",buf1);
printf("\n Cat file1 is \n hai");
write(fd[0], buf1, strlen(buf1));
lseek(fd[0], SEEK_SET, 0);
read(fd[0], buf2, sizeof(buf1));
write(fd[1], buf2, sizeof(buf2));
close(fd[0]);
close(fd[1]);
printf("\n");
return 0;
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:2 SHORTEST JOB FIRST SCHEDULING
PROGRAM:
#include<stdio.h>
#include<conio.h>
struct process
{
int pid; int bt;
int wt; int tt;
}p[10],temp;
int main()
{
int i,j,n,totwt,tottt;
float avg1,avg2;
clrscr();
printf("\nEnter the number of process:\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf ("\n Enter the burst time:\t");
scanf("%d",&p[i].bt);
}
for(i=1;i<n;i++)
{ for(j=i+1;j<=n;j++)
{ if(p[i].bt>p[j].bt)
{ temp.pid=p[i].pid;
p[i].pid=p[j].pid;
III BCA OPERATING SYSEM LAB V SEMESTER
p[j].pid=temp.pid;
temp.bt=p[i].bt;
p[i].bt=p[j].bt;
p[j].bt=temp.bt;
}
}
}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;
}
i=1;
totwt=tottt=0;
printf("\nProcess id \tbt \twt \ttt");
while(i<=n)
{
printf("\n\t%d \t%d \t%d t%d\n",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;}
avg1=totwt/n;
avg2=tottt/n;
printf("\nAVG1=%f\t AVG2=%f",avg1,avg2);
getch();
return 0;
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
enter the number of process 3
enter the burst time: 2
enter the burst time: 4
enter the burst time: 6
processed bt wt tt
1 2 0 2
2 4 2 6
3 6 6 12
AVG1=2.000000 AVG2=6.000000
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:3 FIRST COME FIRST SERVE SCHEDULING
PROGRAM :
#include<stdio.h>
struct process
{
int pid;
int bt;
int wt,tt;
}
p[10];
int main()
{
int i,n,totwt,tottt,avg1,avg2; clrscr();
printf("enter the no of process \n"); scanf("%d",&n);
for(i=1;i<=n;i++)
{ p[i].pid=i;
printf("enter the burst time n"); scanf("%d",&p[i].bt);
}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt; p[i].tt=p[i].bt+p[i].wt;
i++;
}
i=1;
totwt=tottt=0;
printf("\n processid \t bt\t wt\t tt\n"); while(i<=n)
{
printf("\n\t%d \t%d \t%d \t%d",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
III BCA OPERATING SYSEM LAB V SEMESTER
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;}
avg1=totwt/n; avg2=tottt/n; printf("\navg1=%d \t avg2=%d
\t",avg1,avg2); getch();
return 0;
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
enter the no of process 3
enter the burst time 2
enter the burst time 4
enter the burst time 6
Processid bt wt tt
1 2 0 2
2 4 2 6
3 6 6 12
avg1=2 avg2=6
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:4 ROUND ROBIN SCHEDULING ALGORITHM
PROGRAM :
#include<stdio.h>
#include<conio.h>
struct process
{
int pid,bt,tt,wt;
};
int main()
{
struct process x[10],p[30];
int i,j,k,tot=0,m,n;
float wttime=0.0,tottime=0.0,a1,a2;
clrscr();
printf("\nEnter the number of process:\t");
scanf("%d",&n);
for(i=1;i<=n;i++){
x[i].pid=i;
printf("\nEnter the Burst Time:\t");
scanf("%d",&x[i].bt);
tot=tot+x[i].bt;
}
printf("\nTotal Burst Time:\t%d",tot);
p[0].tt=0;
k=1;
printf("\nEnter the Time Slice:\t");
scanf("%d",&m);
for(j=1;j<=tot;j++)
{
for(i=1;i<=n;i++)
III BCA OPERATING SYSEM LAB V SEMESTER
{
if(x[i].bt !=0)
{
p[k].pid=i;
if(x[i].bt-m<0)
{
p[k].wt=p[k-1].tt;
p[k].bt=x[i].bt;
p[k].tt=p[k].wt+x[i].bt;
x[i].bt=0;
k++;
}
else
{
p[k].wt=p[k-1].tt;
p[k].tt=p[k].wt+m;
x[i].bt=x[i].bt-m;
k++;
}
}
}
}
printf("\nProcess id \twt \ttt");
for(i=1;i<k;i++){
printf("\n\t%d \t%d \t%d",p[i].pid,p[i].wt,p[i].tt);
wttime=wttime+p[i].wt;
tottime=tottime+p[i].tt;
a1=wttime/n;
a2=tottime/n;
}
printf("\n\nAverage Waiting Time:\t%f",a1);
III BCA OPERATING SYSEM LAB V SEMESTER
printf("\n\nAverage TurnAround Time:\t%f",a2);
getch();
return 0;
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
enter the no of process3
enter the burst time3
enter the burst time5
enter the burst time7
total burst time : 15
enter the time slice: 2
process id wt tt
1 0 2
2 2 4
3 4 6
1 6 7
process id wt tt
2 7 9
3 9 11
2 11 12
3 12 14
3 14 15
avg waiting time: 21.666666
avg turnaround time: 26.666666
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:5 PRIORITY SCHEDULING ALGORITHM
PROGRAM:
#include<stdio.h>
#include<conio.h>
struct process
{
int pid;
int bt;
int wt;
int tt;
int prior;
}
p[10],temp;
int main()
{
inti,j,n,totwt,tottt,arg1,arg2;
clrscr();
printf("enter the number of process");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf("enter the burst time");
scanf("%d",&p[i].bt);
printf("\n enter thepriority");
scanf("%d",&p[i].prior);
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
III BCA OPERATING SYSEM LAB V SEMESTER
{
if(p[i].prior>p[j].prior)
{
temp.pid=p[i].pid;
p[i].pid=p[j].pid;
p[j].pid=temp.pid;
temp.bt=p[i].bt;
p[i].bt=p[j].bt;
p[j].bt=temp.bt;
temp.prior=p[i].prior;
p[i].prior=p[j].prior;
p[j].prior=temp.prior;
}
}
}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;
}
i=1;
totwt=tottt=0;
printf("\n process to \t bt \t wt \t tt");
while(i<=n)
{
printf("\n\t%d\t %d\t %d\t %d",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
III BCA OPERATING SYSEM LAB V SEMESTER
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
}
arg1=totwt/n;
arg2=tottt/n;
printf("\n arg1=%d \t
arg2=%d\t",arg1,arg2);
getch();
return 0;
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
enter the no of process:3
enter the burst time:2
enter the priority:3
enter the burst time:4
enter the priority:1
enter the burst time:6
enter the priority:2
process to bt wt tt
14044
2 6 4 10 14
3 2 10 12 22
avg1=4 avg2=8
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:6 READER / WRITER PROBLEM USING SEMOPHERES
PROGRAM:
#include<pthread.h>
#include<semaphore.h>
#include<stdio.h>
void *reader(void *);
void *writer(void *);
int readcount=0,writecount=0,sh_var=5,bsize[5];
sem_t x,y,z,rsem,wsem;
pthread_t r[3],w[2];
void *reader(void *i)
{
printf("\n ");
printf("\n\n reader-%d is reading",i);
sem_wait(&z);
sem_wait(&rsem);
sem_wait(&x);
readcount++;
if(readcount==1)
sem_wait(&wsem);
sem_post(&x);
sem_post(&rsem);
sem_post(&z);
printf("\nupdated value : %d",sh_var);
sem_wait(&x);
III BCA OPERATING SYSEM LAB V SEMESTER
readcount--;
if(readcount==0)
sem_post(&wsem);
sem_post(&x);
}
void *writer(void *i)
{
printf("\n\n writer-%d is writing",i);
sem_wait(&y);
writecount++;
if(writecount==1)
sem_wait(&rsem);
sem_post(&y);
sem_wait(&wsem);
sh_var=sh_var+5;
sem_post(&wsem);
sem_wait(&y);
writecount--;
if(writecount==0)
sem_post(&rsem);
sem_post(&y);
}
int main()
{
sem_init(&x,0,1);
sem_init(&wsem,0,1);
sem_init(&y,0,1);
sem_init(&z,0,1);
III BCA OPERATING SYSEM LAB V SEMESTER
sem_init(&rsem,0,1);
pthread_create(&r[0],NULL,(void *)reader,(void *)0);
pthread_create(&w[0],NULL,(void *)writer,(void *)0);
pthread_create(&r[1],NULL,(void *)reader,(void *)1);
pthread_create(&r[2],NULL,(void *)reader,(void *)2);
pthread_create(&r[3],NULL,(void *)reader,(void *)3);
pthread_create(&w[1],NULL,(void *)writer,(void *)3);
pthread_create(&r[4],NULL,(void *)reader,(void *)4);
pthread_join(r[0],NULL);
pthread_join(w[0],NULL);
pthread_join(r[1],NULL);
pthread_join(r[2],NULL);
pthread_join(r[3],NULL);
pthread_join(w[1],NULL);
pthread_join(r[4],NULL);
return(0);
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
student@mmcoe-desktop:~$ gcc rw1.c -lpthread
student@mmcoe-desktop:~$ ./a.out
reader-0 is reading
updated value : 5
writer-0 is writing
reader-1 is reading
updated value : 10
reader-2 is reading
updated value : 10
reader-3 is reading
updated value : 10
writer-3 is writing
reader-4 is reading
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:7 BANKER’S ALGORITHM FOR DEADLOCK AVOIDANCE
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();
printf("\n ENTER THE NO. OF PROCESSES:");
scanf("%d",&n);
printf("\n ENTER THE NO. OF RESOURCES:");
scanf("%d",&r);
for(i=0;i<n;i++)
{
printf("PROCESS %d \n",i+1);
for(j=0;j<r;j++)
{
printf("MAXIMUM VALUE FOR RESOURCE %d:",j+1);
scanf("%d",&p[i].max[j]);
}
for(j=0;j<r;j++)
{
printf("ALLOCATED FROM RESOURCE %d:",j+1);
scanf("%d",&p[i].a1[j]);
p[i].need[j]=p[i].max[j]-p[i].a1[j];
}
III BCA OPERATING SYSEM LAB V SEMESTER
}
for(i=0;i<r;i++)
{
printf("ENTER TOTAL VALUE OF RESOURCE %d:",i+1);
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;
}
printf("\n\t RESOURCES ALLOCATED NEEDED TOTAL AVAIL");
for(i=0;i<n;i++)
{
printf("\n P%d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].max[j]);
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]);
}
III BCA OPERATING SYSEM LAB V SEMESTER
printf(" ");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",av[j]);
}
}
printf("\n\n\t AVAIL BEFORE\T AVAIL AFTER ");
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])
cn++;
if(p[i].max[j]==0)
cz++;
}
if(cn==0 && cz!=r)
{
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]);
III BCA OPERATING SYSEM LAB V SEMESTER
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].after[j]);
cn=0;
cz=0;
c++;
break;
}
else
{
cn=0;cz=0;
}
}
}
if(c==n)
printf("\n THE ABOVE SEQUENCE IS A SAFE SEQUENCE");
else
printf("\n DEADLOCK OCCURED");
getch();
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
Expected Input and Output:
ENTER THE NO. OF PROCESSES:5
ENTER THE NO. OF RESOURCES:3
PROCESS 1
MAXIMUM VALUE FOR RESOURCE 1:7
MAXIMUM VALUE FOR RESOURCE 2:5
MAXIMUM VALUE FOR RESOURCE 3:3
ALLOCATED FROM RESOURCE 1:0
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:0
PROCESS 2
MAXIMUM VALUE FOR RESOURCE 1:3
MAXIMUM VALUE FOR RESOURCE 2:2
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:2
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:0
PROCESS 3
MAXIMUM VALUE FOR RESOURCE 1:9
MAXIMUM VALUE FOR RESOURCE 2:0
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:3
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:2
PROCESS 4
MAXIMUM VALUE FOR RESOURCE 1:2
MAXIMUM VALUE FOR RESOURCE 2:2
III BCA OPERATING SYSEM LAB V SEMESTER
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:2
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:1
PROCESS 5
MAXIMUM VALUE FOR RESOURCE 1:4
MAXIMUM VALUE FOR RESOURCE 2:3
MAXIMUM VALUE FOR RESOURCE 3:3
ALLOCATED FROM RESOURCE 1:0
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:2
ENTER TOTAL VALUE OF RESOURCE 1:10
ENTER TOTAL VALUE OF RESOURCE 2:5
ENTER TOTAL VALUE OF RESOURCE 3:7
RESOURCES ALLOCATED NEEDED TOTAL AVAIL
P1 753 010 743 1057 332
P2 322 200 122
P3 902 302 600
P4 222 211 011
P5 433 002 431
AVAIL BEFORET AVAIL AFTER
P 2 210 532
P 4 521 743
P 1 000 753
P 3 153 1055
P 5 624 1057
THE ABOVE SEQUENCE IS A SAFE SEQUENCE
III BCA OPERATING SYSEM LAB V SEMESTER
EX NO: 8 FIFO PAGE REPLACEMENT ALGORITHMS
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();
printf("\n \t\t\t FIFI PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of frames ... ");
scanf("%d",&nof);
printf("Enter number of Pages.\n");
scanf("%d",&nor);
printf("\n Enter the Page No. ");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("\nThe given Pages are:");
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;
printf("\n\t page no %d->\t",ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
III BCA OPERATING SYSEM LAB V SEMESTER
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]);
}
}
printf("\n\n\t\t No.of pages faults...%d",pf);
getch();
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
FIFO PAGE REPLACEMENT ALGORITHM
Enter no.of frames....
4
Enter number of reference string..
6
Enter the reference string..
564123
The given reference string:
...................................... 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
No.of pages faults .. 6
III BCA OPERATING SYSEM LAB V SEMESTER
EX NO:9 LRU PAGE REPLACEMENT ALGORITHM
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();
printf("\n\t\t\t LRU PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of Frames ... ");
scanf("%d",&nof);
printf(" Enter no.of reference string..");
scanf("%d",&nor);
printf("\n Enter reference string..");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("\n\n\t\t LRU PAGE REPLACEMENT ALGORITHM ");
printf("\n\t The given reference string:");
printf("\n..................................................");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
{
frm[i]=-1;
lrucal[i]=0;
}
for(i=0;i<10;i++)
recent[i]=0;
III BCA OPERATING SYSEM LAB V SEMESTER
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\t Reference 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=lruvictim();
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
recent[ref[i]]=i;
}
printf("\n\n\t No.of page faults...%d",pf);
getch();
}
int lruvictim()
III BCA OPERATING SYSEM LAB V SEMESTER
{
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;
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
LRU PAGE REPLACEMENT ALGORITHM
Enter no.of Frames ... 3
Enter no.of reference string. 6
Enter reference string..
654231
LRU PAGE REPLACEMENT ALGORITHM
The given reference string:
…………………. 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
No. of page faults . 6
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:10 FIRST FIT ALGORITHM FOR MEMORY MANAGEMENT
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
III BCA OPERATING SYSEM LAB V SEMESTER
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:11 BEST FIT ALGORITHM FOR MEMORY MANAGEMENT
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
clrscr();
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
III BCA OPERATING SYSEM LAB V SEMESTER
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for(i=1;i<=nf && ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4
File No File Size Block No Block Size Fragment
1 1 2 2 1
2 4 1 5 1
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:12 WORST FIT ALGORITHM FOR MEMORY MANAGEMENT
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
III BCA OPERATING SYSEM LAB V SEMESTER
for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
ff[i]=j;
highest=temp;
}
}
}
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4
File No File Size Block No Block Size Fragment
1 1 3 7 6
2 4 1 5 1
III BCA OPERATING SYSEM LAB V SEMESTER
EX.NO:13 INTERPROCESS COMMUNICATION USING PIPES
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<string.h>
main()
{
int p1[2],p2[2],p3[2],p4[2];
int i,j=0,k=0,l=0;
char r[10],s[10],t[10],u[10];
printf("\t PROCESS 1.ENTER THE STRING");
scanf("%s",r);
pipe(p1);
pipe(p2);
write(p1[1],r,sizeof(r));
write(p2[1],r,sizeof(r));
int a=fork();
if(a==0)
{
printf("\n\t PROCESS 2:it splits the given string\n");
read(p1[0],r,sizeof(r));
int n=strlen(r);
for(i=0;i<n/2;i++)
{
s[i]=r[i];
}
for(i=n/2;i<=n;i++)
{
t[j++]=r[i];
}
III BCA OPERATING SYSEM LAB V SEMESTER
pipe(p3);
pipe(p4);
write(p3[1],s,sizeof(s));
write(p4[1],t,sizeof(t));
int b=fork();
if(b==0)
{
printf("p4 %d\t",getpid());
printf("p2 %d\n",getppid());
read(p3[0],s,sizeof(s));
printf("\t PROCESS 4:sub string \t %s \t",s);
printf("no of char=%d \n",strlen(s));
}
else
{
int c=fork();
if(c==0)
{
printf("p5 %d\t",getpid());
printf("p2 %d\n",getppid());
read(p4[0],t,sizeof(t));
printf("\t PROCESS 5:sub string \t %s \t",t);
printf("no of char=%d \n",strlen(t));
}
else
{
wait();
printf("p2 %d\t",getpid());
printf("p1 %d\n",getppid());
} }}
else
III BCA OPERATING SYSEM LAB V SEMESTER
{
wait();
int d=fork();
if(d==0)
{
printf("p3 %d\t",getpid());
printf("p1 %d\n",getppid());
read(p2[0],r,sizeof(r));
for(i=strlen(r)-1;i>=0;i--)
{
u[l++]=r[i];
}
for(i=0;i<strlen(r);i++)
{
if(u[i]==r[i])
k++;
else
continue;
}
if(k==strlen(r))
printf("\t PROCESS 3: the given string is palindrome\n");
else
printf("\t PROCESS 3: the given string is not palindrome\n");
}
else
{
printf("p1 %d\t",getpid());
printf("kernal %d\t\n",getppid());
}
}}
III BCA OPERATING SYSEM LAB V SEMESTER
OUTPUT:
Process 1: enter the string ARUN
Process 2: it splits the string
P4 8137 p2 8136
Process 3: sub string a r no of char=2
P5 8138 p2 8136
Process 4; substring u n no of char=2
P2 8136 p1 8132
P3 8139 p1 8132
Process 3: the given string is not palindrome
Process 1: enter the string MADAM
Process 2: it splits the string
P4 8137 p2 8136
Process 4: sub string m a no of char=2
P5 8138 p2 8136
Process 5: sub string dam no of char=3
P2 8136 p1 8132
P3 8139 p1 8132
Process 3: the given string is palindrome
III BCA OPERATING SYSEM LAB V SEMESTER