0% found this document useful (0 votes)
8 views78 pages

Os Record

Uploaded by

rkalpana.se
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views78 pages

Os Record

Uploaded by

rkalpana.se
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 78

CONTENTS

PAGE
S.NO DATE EXPERIMENTNAME MARKS SIGNATURE
NO

1 LINUXCOMMANDS

2 VARIOUSOPERATIONSINSYSTEMCALLS
USING UNIX OPERATING SYSTEM

3 I/OSYSTEMCALLS

4(a) FCFSSCHEDULLINGALGORITHM

(b) SJFSCHEDULLINGALGORITHM

5(a) ROUNDROBINSCHEDULLINGALGORITHM

(b) PRIORITYSCHEDULLINGALGORITHM

6 INTER-PROCESSCOMMUNICATION

7 PRODUCERCONSUMERPROBLEMUSING
SEMAPHORES

8 FIRSTFITALGORITHMINMEMORY
MANAGEMENT

9(a) BESTFITALGORITHMINMEMORY
MANAGEMENT

(b) WORSTFITALGORITHMINMEMORY
MANAGEMENT

10 CONTIGUOUSFILEALLOCATION
TECHNIQUE
Ex.Num.:1 LINUXCOMMANDS
Date:

 AIM:Executionofvariousfile/directoryhandlingcommands.

 ALGORITHM:

-Starttheprogram
-Selectapplication->terminal
-Thefollowingarethebasiclinuxcommandsthatwehavetoexecuteintheterminal.

PROCEDURE:
1) pwdCOMMAND:
pwd-PrintWorkingDirectory.pwdcommandprintsthefullfilenameofthecurrent
working directory.
SYNTAX:TheSyntaxispwd[options]

2) cd COMMAND:
cdcommandisusedtochangethedirectory.
SYNTAX:TheSyntaxiscd[directory|~|./|../|- ]

3) lsCOMMAND:
lscommandliststhefilesanddirectoriesundercurrentworking directory.
SYNTAX:TheSyntaxisls[OPTIONS]... [FILE]

OPTIONS:
-l:Listsallthefiles,directoriesandtheirmode,Numberoflinks, owner
of the file, file size, Modified date and time and filename.
-t:Listsinorderof lastmodificationtime.
-a:Listsallentries includinghiddenfiles.
-d:Listsdirectoryfiles insteadof contents.
-p:Putsslashattheendof eachdirectories.
-u:Listinorder oflastaccesstime.
-i:Displayinodeinformation.

4) rmCOMMAND:
rmlinuxcommand isusedtoremove/deletethefilefromthedirectory.
SYNTAX: TheSyntaxisrm [options..][file| directory]

OPTIONS:
-f:Removeallfiles inadirectorywithoutprompting theuser.
-i:Interactive.Withthisoption,rmpromptsforconfirmationbeforeremovinganyfiles.

5) mv COMMAND:
mv command which is short for move. It is used to move/rename file from one
directorytoanother.mvcommandisdifferentfromcpcommand asitcompletelyremovesthefile from
the source and moves to the directory specified, where cp command just copies the content from
one file to another.
SYNTAX:TheSyntaxismv[-f][-i]oldname newname

OPTIONS:
-f:Thiswillnotpromptbeforeoverwriting(equivalentto--reply=yes).
mv-f willmovethefile(s)withoutpromptingevenifitiswritingoveranexisting target.
-i:Promptsbeforeoverwriting anotherfile.

6) catCOMMAND:
catlinuxcommandconcatenatesfilesandprintitonthestandard output.
SYNTAX:TheSyntaxiscat[OPTIONS][FILE]...

OPTIONS:
-A:Show all.
-b:Omits linenumbersforblankspaceintheoutput.
-E:Displays a$(dollarsign)attheend ofeachline.
-n:Linenumbersforalltheoutput lines.

7) cmpCOMMAND:
cmplinuxcommandcomparestwofilesandtellsyou whichlinenumbers are
different.
SYNTAX:TheSyntaxiscmp[options..]file1file2

OPTIONS:
- c:Outputdifferingbytesascharacters.
- l:Printthebytenumber(decimal)andthedifferingbytevalues
(octal) for each difference.
- s:Printsnothingfordifferingfiles,returnexitstatusonly.

8) cp COMMAND:
cpcommandcopyfilesfromonelocationtoanother.Ifthe destinationisanexisting file,
then the file is overwritten; if the destination is
anexistingdirectory,thefileiscopiedintothedirectory(thedirectoryisnot overwritten).
SYNTAX:TheSyntaxiscp[OPTIONS]...SOURCE DEST

10) echo COMMAND:


echocommandprintsthegiveninputstringtostandardoutput.
SYNTAX:TheSyntaxisecho[options..][string]

11)mkdir COMMAND:
mkdircommand isused tocreateoneormoredirectories.
SYNTAX:TheSyntaxismkdir[options] directories

OPTIONS:
-m:Settheaccess modeforthenewdirectories.
-p:Createinterveningparentdirectoriesiftheydon'texist.
-v:Printhelpmessagefor eachdirectory created.

12) pasteCOMMAND:
pastecommand is usedtopastethecontentfromonefiletoanotherfile.Itis also used to
set column format for each line.
SYNTAX:TheSyntaxispaste[options]

OPTIONS:
-s:Pasteonefileatatimeinsteadof in parallel.
-d:Reusecharacters fromLISTinsteadofTABs.

13) rmdirCOMMAND:
rmdircommandisusedtodelete/removeadirectoryandits subdirectories.
SYNTAX:TheSyntaxisrmdir[options..]Directory

OPTIONS:
-p:Allowuserstoremovethedirectorydirnameanditsparent
directories which become empty.

Result:
Inthiswaywecanrundifferentfileanddirectoryhandlingcommandsandseethe
outputonstandardoutputwindow. Ex.
Num.: 2
Date:
SYSTEM CALL OF UNIX OPERATING SYSTEM
(GETPID,GETPPID,FORK,EXECL,EXIT,WAITCLOSE,OPENDIR,READDIR)

AIM:TowriteaC-Programforgetpid,getppid,fork,execl,exit,wait,close,opendir,readdirsystem calls in
Linux operating system.

i. ALGORITHMFORGETPIDANDGETPPID:

-Includenecessaryheaderfileforusingsystem calls.
-Makenecessarydeclarations.
-GettheProcessidentificationnumberandparentprocessidentificationnumberusing getpid()
and getppid() system calls.
-Displaytheid’s.
-Closetheprogram.

 PROGRAM:
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>Void
main()
{
Int pid,ppid;
pid=getpid();
ppid=getppid();
printf(“\nProcessIdis %d \n”, pid);
printf(“\nParentProcessId is%d\n”,ppid);
}

OUTPUT:
ii. ALGORITHMFORFORKSYSTEMCALL:
-Includenecessary declarations.
-Includenecessaryheaderfilesforusingsystemcalls.
-Ask()systemcallis used tocreateanew process.
-Displaytheresults.
-Closetheprogram.

 PROGRAM:
#include<stdio.h>
#include<unistd.h>
int main()
{
intid;
printf(“Helloworld!!\n”);
id=fork();
if(id>0)
{
printf(“\nThisisparentsection[Processidis%d]\n”,getpid);
}
elseif(id==0)
{
printf(“\nForcreated[Processidid%d]\n”,getpid()); printf(“\nFork
parent process id :%d\n”,getppid());
}
else
{
printf(“\nForkcreationfailed!!!\n”);
}
return0;
}

OUTPUT:
i. ALGORITHMFOREXECLSYSTEMCALL:

-Includenecessaryheaderfilesforusingsystemcalls.
-Makenecessarydeclarations.
-‘exec’systemcallwillleadanewprogramintocurrentrunningprogramwiththeone
specified.
-Displaytheresult.
-Closetheprogram.

 PROGRAMS:
#include<unistd.h>
#include<sys/types.h>
#include<stdio.h>
main()
{
execl(“/bin/date”,”date”,NULL);
}

OUTPUT:
IV. ALGORITHMFORWAITSYSTEMCALLS:
-Includenecessaryheaderfilesforusingsystemcalls.
-Makenecessary declarations.
-Systemcallwait()isusedtocontroltheexecutionofchildprocesswhichrunsinparent
process.The wait() forces the parent to suspend execution until the child and finished
wait() returns the process id of a child that finished.
-Displaytheoutput.
-Closetheprograms.

 PROGRAM:
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
main()
{
int pid,i=0;
printf(“\nReadytoFork”);
pid=fork();
if(pid==0)
{
printf(“\nChilkdStarts\n”);
for(i=0;i<1;i++)
{
printf(“\nChildends..”);
}
}
else
{
wait(0);
for(i=0;i<1;i++)
{
printf(“\nParentprocessends”);
}
}
}

OUTPUT:
V. ALGORITHMFOREXITSYSTEMCALL:
-Includenecessaryfiles forusingsystem calls.
-Makenecessarydeclarations.
-exit()systemcallendsaprocessandreturnsastatustoitsparent9a0hostenvironment.
-Displaytheresult.
-End the program.

 PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf(“Start the program….\n”);
printf(“Exitingtheprogram….\n”); exit(0);
printf(“Endtheprogram…..\n”);
return(0);
}

OUTPUT:
VI. OPEN DIR(),READDIR(),CLOSE DIR():
-Thissystemcallisusedtoopenadirectoryandreturnapointertodirectorystream.
Thestreamis positionedatthefirstentryinthedirectories.

 ALGORITHM:

-Includenecessaryheaderfilesforusingthesystem calls.
-Makenecessarydeclaration.
-opendir()isusedtoopenthedirectoryandreaddir()isused toread thedirectory.
-Displaytheresult.
-Closetheprogram.

 PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<dirent.h>
#include<fcntl.h>
intmain(intargc,char*argr[])
{
DIR*dir;
structdirent*sd;
dir=opendir(“.”);
if(dir==NULL)
{
printf(“\nErrorenabletoopen”);
exir(1);
}
while((sd=readdir(dir))!=NULL)
{
printf(“%s\n”,sd->d_name);
}
close(dir);
return 0;
}

OUTPUT:
 RESULT:
ThustheC-Programforgetpid(),getppid(),fork(),execl(),exit(),wait(),close(),
opendir(), readdir() is executed and the output has been successfully verified.

Ex.Num.:3 I/OSYTEMCALLS OFOS(OPEN,READ,WRITE)


Date:

 AIM:TowriteaprogramusingtheI?OSystemcallsof operatingsystem(open/read/write).

 ALGORITHM:

-Starttheprogram.
-I/OSystemcallslikeopen,read,writeareusedforcreating,reading,andwritingafile.
-Therecord systemcalls doesallI/Ooperations.
-Closesystemcallis usedtoclosethefile.
-Displaytheoutput.
-Stoptheprogram.

 PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<sys/vio.h>
#include<unistd.h>
intmain(intargc,char*argr[])
{
Intfd;
Charbuf[14];
/*write*/
fd=open(“Myfile.txt”,O_CREATE|O_WRONLY,0644);
if(fd==-1)
{
printf(“\nFailedtocreateandopenthefile”);
exit(1);
}
write(fd,”\nHelloWorld”,13);
close(fd);
//read
fd=open(“Myfile.text”,O_RDONLY);
if(fd==-1)
{
printf(“\nFailedtoopen”);
exit(1);
}
read(fd,buf,13);
buf[13]=’\0’;
close(fd);
printf(“\nbuf:%s\n”,buf);
return(0);
}

OUTPUT:
 RESULT:
ThusC-Programhasbeenwrittenusingopen(),read(),write(),close()systemcalland the
output was verified successfully.
Ex.Num.:4(a) FCFSSCHEDULLINGALGORITHM
Date:

 AIM:Towriteaprogramforimplementing FCFSscheduling algorithm.

 ALGORITHM:

1. Starttheprocess.
2. Declarethearraysize.
3. Getthenumberofelementstobeinserted.
4. Selecttheprocessthatfirstarrivedinthereadyqueue
5. Maketheaveragewaitingthelength ofnextprocess.
6. Startwiththefirstprocessfromit’sselectionasaboveandletotherprocessto be in
queue.
7. Calculatethetotalnumberofbursttime.
8. Displaythevalues.
9. Stoptheprocess.
 PROGRAM:

#include<stdio.h>
main()
{
floatavgwt,avgtt;
charpname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
printf("\n\n Enter the number of processes: ");
scanf("%d",&n);
printf("\n\nEntertheNAME,BURSTTIMEandARRIVALTIMEoftheprocess");
for(i=0;i<n;i++)
{
printf("\n\n NAME : ");
scanf("%s",&pname[i]);
printf("\n\n BURST TIME : ");
scanf("%d",&bt[i]);printf("\n\
nARRIVALTIME:");
scanf("%d",&at[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(at[i]>at[j])
{
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
strcpy(c[i],pname[i]);
Strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}
}
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i]-at[i]);
sbt=sbt+(wt[i+1]-at[i]);
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
}
avgwt=(float)sum/n;
avgtt=(float)sbt/n;
printf("\n\n Average waiting time = %f",avgwt);
printf("\n\nAverageturn-aroundtime=%f",avgtt);
printf("\n\n GANTT CHART\n");
for(i=0;i<n;i++) printf("|\t
%s\t",pname[i]); printf("\
n"); for(i=0;i<n;i++)
printf("%d\t\t",wt[i]);
printf("%d\n",ss);
printf("\n");
}
OUTPUT:
 RESULT:
ThustheprogramforimplementingFCFSschedulingalgorithmwaswrittenand
successfully executed.
Ex.Num.:4(b) SJFSCHEDULLINGALGORITHM
Date:

 AIM:TowriteaprogramforimplementingSJFscheduling algorithm.

 ALGORITHM:

1. Starttheprocess.
2. Declarethearraysize.
3. Getthenumberofelementstobeinserted
4. Selecttheprocesswhichhaveshortestburstwillexecutefirst.
5. IftwoprocesshavesameburstlengththenFCFSscheduling algorithm used.
6. Maketheaveragewaitingthelength ofnextprocess.
7. Startwiththefirstprocessfromit’sselectionasaboveandletotherprocesstobein
queue.
8. Calculatethetotalnumberofbursttime.
9. Displaythevalues.
10. Stoptheprocess.
 PROGRAM:

#include<stdio.h>voi

d main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enternumberofprocess:");
scanf("%d",&n);

printf("\nEnterBurstTime:\n");
for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
}

for(i=0;i<n;i++)
{
pos=i; for(j=i+1;j<n;j+
+)
{
if(bt[j]<bt[pos])
pos=j;
}

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0;

for(i=1;i<n;i++)
{
wt[i]=0; for(j=0;j<i;j+
+)
wt[i]+=bt[j];
total+=wt[i];
}

avg_wt=(float)total/n;
total=0;

printf("\nProcess\t Burst Time \tWaitingTime\tTurnaroundTime");


for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\np%d\t\t%d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=(float)total/n;
printf("\n\nAverage Waiting Time=%f",avg_wt); printf("\
nAverageTurnaroundTime=%f\n",avg_tat);
}
OUTPUT:
 RESULT:
ThustheprogramforimplementingSJFschedulingalgorithmwaswrittenand
successfully executed.
Ex.Num.:5(a) ROUNDROBINSCHEDULLINGALGORITHM
Date:

 AIM:Towriteaprogramforimplementtheround robinscheduling algorithm

 ALGORITHM:
1. Starttheprocess.
2. Declarethearraysize.
3. Getthenumberofelementstobeinserted.
4. Getthevalue.
5. Setthetimesharingsystemwithpreemption.
6. Definequantumisdefinedfrom10to100ms.
7. Declarethequeueas acircular.
8. MaketheCPUschedulergoesaroundthereadyqueueallocatingCPUtoeachprocessfor the
time interval specified.
9. MaketheCPUschedulerpicksthefirstprocessandsetstimetointerrupt afterquantum
expired dispatches the process.
10. Iftheprocesshasburstlessthanthetimequantumthantheprocess releasesthe
CPU.
 PROGRAM:

int main()
{

intcount,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("EnterArrivalTimeandBurstTimeforProcessProcessNumber%d:",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum); printf("\n\nProcess\t|
TurnaroundTime|WaitingTime\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum&&rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
elseif(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0&&flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("AvgTurnaroundTime=%f",turnaround_time*1.0/n);

return0;
}
OUTPUT:
 RESULT:
ThustheprogramforimplementingRRschedulingalgorithmwaswrittenand
successfully executed.
Ex.Num.:5(b) PRIORITYSCHEDULLINGALGORITHM
Date:

 AIM:Towriteaprogramforimplementthepriorityscheduling algorithm.

 ALGORITHM:
1. Starttheprocess.
2. Declarethearray size.
3. Getthenumberofelementstobeinserted.
4. Getthepriorityforeachprocessandvalue
5. startwiththehigherpriorityprocessfromit’sinitialpositionletother processtobe
queue.
6. calculatethetotalnumberofbursttime.
7. Displaythevalues
8. Stoptheprocess.
 PROGRAM:

#include<stdio.h>i

nt main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);

printf("\nEnterBurstTimeandPriority\n");
for(i=0;i<n;i++)
{
printf("\nP[%d]\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1;
}

for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];

total+=wt[i];
}

avg_wt=total/n;
total=0;

printf("\nProcess\t Burst Time \tWaitingTime\tTurnaroundTime");


for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\nP[%d]\t\t%d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=total/n;
printf("\n\nAverage Waiting Time=%d",avg_wt); printf("\
nAverageTurnaroundTime=%d\n",avg_tat);

return0;
}
OUTPUT:
 RESULT:
ThustheprogramforimplementingPRIORITYschedulingalgorithmwaswritten and
successfully executed.
Ex. Num.:6 INTERPROCESSCOMMUNICATION
Date: (USINGSHAREDMEMORY,PIPESORMESSAGE QUEUES)

 AIM:TowriteaprogramfordevelopingApplicationusingInterProcesscommunication with
pipes.

 ALGORITHM:

1. Starttheprogram.
2. Readtheinputfromparentprocessandperforminchildprocess.
3. Writethedateinparentprocessandreaditinchildprocess.
4. FibonacciSerieswasperformedinchildprocess.
5. Stoptheprogram.
 PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/uio.h>
#include<sys/types.h>
main()
{
intpid,pfd[2],n,a,b,c;
if(pipe(pfd)==-1)
{
printf("\nErrorinpipeconnection\n");
exit(1);
}
pid=fork();
if(pid>0)
{
printf("\nParent Process"); printf("\n\
n\tFibonacci Series"); printf("\
nEnterthelimitfortheseries:");
scanf("%d",&n);
close(pfd[0]);
write(pfd[1],&n,sizeof(n));
close(pfd[1]);
exit(0);
}
else
{
close(pfd[1]);
read(pfd[0],&n,sizeof(n));
printf("\nChildProcess");
a=0;
b=1;
close(pfd[0]); printf("\
nFibonacciSeriesis:"); printf("\
n\n%d\n%d",a,b); while(n>2)
{
c=a+b; printf("\n
%d",c); a=b;
b=c;
n--;
}
}
}
OUTPUT:
 RESULT:
ThustheprogramfordevelopingApplicationusingInterProcesscommunication with
pipes is written and successfully executed.
Ex.Num.:7PRODUCER-CONSUMER PROBLEMUSINGSEMAPHORES
Date: (USINGUNIXSYSTEMCALLS)

 AIM:TowriteaprogramforImplementtheProducer –Consumerproblemusing
semaphores (using UNIX system calls).

 ALGORITHM:

1. Starttheprocess
2. Initializebuffersize
3. Consumerenters,beforethatproducerbufferwasnotempty.
4. Producerenters,beforecheckconsumerconsumesthebuffer.
5. Stoptheprocess.
 PROGRAM:

#include<stdio.h>
#include<stdlib.h>

intmutex=1,full=0,empty=3,x=0;

int main()
{
intn;
void producer();
voidconsumer();
int wait(int);
int signal(int); printf("\n1.Producer\
n2.Consumer\n3.Exit"); while(1)
{
printf("\nEnteryourchoice:");
scanf("%d",&n);
switch(n)
{
case1:if((mutex==1)&&(empty!=0))
producer();
else
printf("Bufferisfull!!");
break;
case2:if((mutex==1)&&(full!=0))
consumer();
else
printf("Bufferisempty!!");
break;
case3:
exit(0);
break;
}
}

return0;
}

intwait(ints)
{
return(--s);
}

intsignal(ints)
{
return(++s);
}

voidproducer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty); x+
+;
printf("\nProducerproducestheitem%d",x);
mutex=signal(mutex);
}

voidconsumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\nConsumerconsumesitem%d",x);
x--;
mutex=signal(mutex);
}
OUTPUT:
 RESULT:
ThustheprogramforImplementtheProducer –Consumerproblemusing
semaphores (using UNIX system calls) was written and successfully executed.
Ex. Num.:8 FIRSTFITALGORITHMFORMEMEORYMANAGEMENT
Date:

 AIM:Towriteaprogramtoimplementfirstfitalgorithmformemory management.

 ALGORITHM

1. Starttheprocess.
2. Declarethesize.
3. Getthenumberofprocessestobeinserted.
4. Allocatethefirstholethatisbig enoughsearching.
5. Startatthebeginningofthesetofholes.
6. Ifnotstartattheholethatis sharing theperviousfirstfitsearchend.
7. Iflargeenoughthenstopsearchingintheprocedure.
8. Displaythevalues.
9. Stoptheprocess.
 PROGRAM:

#include<stdio.h>i
nt main()
{
intfragments[10],block[10],file[10],m,n,number_of_blocks,
number_of_files, temp;
static int block_arr[10], file_arr[10]; printf("\
nEntertheTotalNumberofBlocks:\t");
scanf("%d", &number_of_blocks); printf("\
nEnter the Total Number of Files:\t");
scanf("%d", &number_of_files);
printf("\nEntertheSizeoftheBlocks:\n");
for(m = 0; m < number_of_blocks; m++)
{
printf("BlockNo.[%d]:\t",m+1);
scanf("%d",&block[m]);
}
printf("EntertheSizeoftheFiles:\n");
for(m = 0; m < number_of_files; m++)
{
printf("FileNo.[%d]:\t",m+1);
scanf("%d",&file[m]);
}
for(m=0; m<number_of_files;m++)
{
for(n=0;n< number_of_blocks;n++)
{
if(block_arr[n]!=1)
{
temp=block[n]-file[m]; if(temp
>= 0)
{
file_arr[m]=n;
break;
}
}
}
fragments[m] = temp;
block_arr[file_arr[m]]=1;
}
printf("\nFileNumber\tFileSize\tBlockNumber\tBlockSize\tFragment"); for(m
= 0; m < number_of_files; m++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",m,file[m],file_arr[m],block[file_arr[m]],
fragments[m]);
}
printf("\n");
return 0;
}
OUTPUT:
 RESULT:
ThustheprogramforImplementfirstfit algorithmformemorymanagementis written
and successfully executed.
Ex.Num.:9(a)BESTFITALGORITHMFORMEMEORYMANAGEMENT
Date:

 AIM:TowriteaprogramforImplementbestfitmemorymanagement

 ALGORITHM:

1. Starttheprocess.
2. Declarethesize.
3. Getthenumberofprocessestobeinserted.
4. Allocatethebestholethatissmallenoughsearching.
5. Startatthebeginningofthesetofholes.
6. Ifnotstartattheholethatissharingthepreviousbestfitsearchendandcomparethe hole in
the list.
7. Ifsmallenoughthenstopsearchingintheprocedure.
8. Displaythevalues.
9. Stoptheprocess.
 PROGRAM:

#include<stdio.h>i
nt main()
{
intfragments[10],block[10],file[10],m,n,number_of_blocks,number_of_files,temp,lowest
=10000;
static int block_arr[10], file_arr[10]; printf("\
nEntertheTotalNumberofBlocks:\t");
scanf("%d", &number_of_blocks); printf("\
nEnter the Total Number of Files:\t");
scanf("%d", &number_of_files);
printf("\nEntertheSizeoftheBlocks:\n");
for(m = 0; m < number_of_blocks; m++)
{
printf("BlockNo.[%d]:\t",m+1);
scanf("%d",&block[m]);
}
printf("EntertheSizeoftheFiles:\n");
for(m = 0; m < number_of_files; m++)
{
printf("FileNo.[%d]:\t",m+1);
scanf("%d",&file[m]);
}
for(m=0; m<number_of_files;m++)
{
for(n=0;n< number_of_blocks;n++)
{
if(block_arr[n]!=1)
{
temp=block[n]-file[m]; if(temp
>= 0)
{
if(lowest>temp)
{
file_arr[m]=n;
lowest= temp;
}
}
}
fragments[m] = lowest;
block_arr[file_arr[m]]=1;
lowest= 10000;
}
}
printf("\nFileNumber\tFileSize\tBlockNumber\tBlockSize\tFragment"); for(m
= 0; m < number_of_files && file_arr[m] != 0; m++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",m,file[m],file_arr[m],block[file_arr[m]],
fragments[m]);
}
printf("\n");
return 0;
}
OUTPUT:
 RESULT:
ThustheprogramforImplementbestfitalgorithmformemorymanagementis written
and successfully executed.
Ex.Num.:9(b) WORSTFITALGORITHMFOR
Date: MEMEORYMANAGEMENT

 AIM:Towriteaprogram forImplementworstfitmemorymanagement.

 ALGORITHM:
1.Starttheprogram.
2.Declarethe size.
3.Getthenumberofprocesses tobeinserted.
4.Allocatethefirstholethatis smallenoughsearching.
5.Ifsmallenoughthenstopsearchingintheprocedure.
6.Displaythevalues.
7.Stop theprogram.
 PROGRAM:

#include<stdio.h>i
nt main()
{
intfragments[10],blocks[10],files[10];
intm,n,number_of_blocks,number_of_files,temp,top=0; static
int block_arr[10], file_arr[10];
printf("\nEntertheTotalNumberofBlocks:\t");
scanf("%d",&number_of_blocks);
printf("EntertheTotalNumberofFiles:\t");
scanf("%d",&number_of_files); printf("\
nEnter the Size of the Blocks:\n"); for(m = 0;
m < number_of_blocks; m++)
{
printf("BlockNo.[%d]:\t",m+1);
scanf("%d",&blocks[m]);
}
printf("EntertheSizeoftheFiles:\n");
for(m = 0; m < number_of_files; m++)
{
printf("FileNo.[%d]:\t",m+1);
scanf("%d",&files[m]);
}
for(m=0; m<number_of_files;m++)
{
for(n=0;n< number_of_blocks;n++)
{
if(block_arr[n]!=1)
{
temp=blocks[n]-files[m];
if(temp >= 0)
{
if(top<temp)
{
file_arr[m]=n;
top = temp;
}
}
}
fragments[m] = top;
block_arr[file_arr[m]]=1;
top =0;
}
}
printf("\nFileNumber\tFileSize\tBlockNumber\tBlockSize\tFragment");
for(m=0; m<number_of_files;m++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",m,files[m],file_arr[m],blocks[file_arr[m]],
fragments[m]);
}
printf("\n");
return 0;
}
OUTPUT:
 RESULT:
ThustheprogramforImplementbestfit algorithmformemorymanagementiswrittenand successfully
executed.
Ex. Num.:10 CONTIGUOUSFILEALLOCATIONTECHNIQUE
Date:

 AIM:Towriteaprogramforimplementthecontiguousfileallocationtechnique.

 ALGORITHM:

1. Starttheprogram
2. Declarethesize
3. Getthenumberoffilestobeinserted.
4. Getthecapacityofeachfile.
5. Getthestarting address.
6. Thefileisallocatedinmemory
7. Thefileisnotallocatedifthecontiguousmemoryisnotavailable.
8. Displaytheresult
9. Stoptheprogram.
 PROGRAM:
#include<stdio.h>
main()
{
intnf,fc[20],mb[100],i,j,k,fb[100], fs[20],mc=0; clrscr();
printf("\nEnterthenumberoffiles:");
scanf("%d",&nf);
for(i=0;i<nf;i++)
{
printf("\nEnterthecapacityoffile%d:",i+1); scanf("%d",&fc[i]);
printf("\nEnterthestartingaddressoffile%d:",i+1);
scanf("%d",&fs[i]);
}
printf("\n---CONTIGUOUSFILEALLOCATION---\n");
for(i=0;i<100;i++)
fb[i]=1;
for(i=0;i<nf;i++)
{
j=fs[i];
{
if(fb[j]==1)
{
for(k=j;k<(j+fc[i]);k++)
{
if(fb[k]==1)
mc++;
}
if(mc==fc[i])
{
for(k=fs[i];k<(fs[i]+fc[i]);k++)
{
fb[k]=0;
}
printf("\nFile%dallocatedinmemory%dto%d...",i+1,fs[i],fs[i]+fc[i]-1);
}
}
else
printf("\nFile%dnotallocatedsince%dcontiguousmemorynotavailablefrom
%d...",i+1,fc[i],fs[i]);
}
mc=0;
}
}
OUTPUT:
 RESULT:
Thustheprogramforcontiguousfileallocationtechniquewaswrittenandsuccessfully
executed.

You might also like