0% found this document useful (0 votes)
7 views

Operating Systems Lab Manual

The document is a lab manual for an Operating Systems course, detailing program outcomes, specific outcomes, and a syllabus for practical experiments using C language on a Linux platform. It includes a list of experiments focused on CPU scheduling algorithms, memory management techniques, file allocation strategies, and process synchronization. The manual aims to provide students with hands-on experience in implementing and understanding key operating system concepts.

Uploaded by

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

Operating Systems Lab Manual

The document is a lab manual for an Operating Systems course, detailing program outcomes, specific outcomes, and a syllabus for practical experiments using C language on a Linux platform. It includes a list of experiments focused on CPU scheduling algorithms, memory management techniques, file allocation strategies, and process synchronization. The manual aims to provide students with hands-on experience in implementing and understanding key operating system concepts.

Uploaded by

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

OPERATING SYSTEMS

LABMANUAL
COMPUTER SCIENCE AND ENGINEERING

Program Outcomes
PO1 Engineeringknowledge:Applytheknowledgeofmathematics,science,engineeringfundamentals,and
anengineeringspecializationtothesolutionofcomplexengineeringproblems.
PO2 Problemanalysis:Identify,formulate,reviewresearchliterature,andanalyzecomplexengineering
problemsreachingsubstantiatedconclusionsusingfirstprinciplesofmathematics,naturalsciences,and
engineeringsciences.
PO3 Design/developmentofsolutions:Designsolutionsforcomplexengineeringproblemsanddesign
systemcomponentsorprocessesthatmeetthespecifiedneedswithappropriateconsiderationforthe
publichealthandsafety,andthecultural,societal,andenvironmentalconsiderations.
PO4 Conductinvestigationsofcomplexproblems:Useresearch-basedknowledgeandresearchmethods
includingdesignofexperiments,analysisandinterpretation ofdata,andsynthesisoftheinformationto
providevalidconclusions.
PO5 Moderntoolusage:Create,select,andapplyappropriatetechniques,resources,andmodern
engineeringandITtoolsincludingpredictionandmodelingtocomplexengineeringactivitieswithan
understandingofthelimitations.
PO6 Theengineerandsociety:Applyreasoninginformedbythecontextualknowledgeto assesssocietal,
health,safety,legalandculturalissuesandtheconsequentresponsibilitiesrelevanttotheprofessional
engineeringpractice.
PO7 Environmentandsustainability:Understandtheimpactoftheprofessionalengineeringsolutionsin
societalandenvironmentalcontexts,anddemonstratetheknowledgeof,andneedforsustainable
development.
PO8 Ethics:Applyethicalprinciplesandcommittoprofessionalethicsandresponsibilitiesandnormsofthe
engineeringpractice.
PO9 Individualandteamwork:Functioneffectivelyasanindividual,andasamemberorleaderindiverse
teams,andinmultidisciplinarysettings.
PO10 Communication:Communicateeffectivelyoncomplexengineeringactivitieswiththeengineering
communityandwithsocietyatlarge,suchas,beingabletocomprehendandwriteeffectivereportsand
designdocumentation,makeeffectivepresentations,andgiveandreceiveclearinstructions.
PO11 Projectmanagementandfinance:Demonstrateknowledgeandunderstandingoftheengineeringand
managementprinciplesandapplythesetoone’sownwork,asamemberandleaderinateam,to manage projects
and in multidisciplinary environments.
PO12 Life-longlearning:Recognizetheneedfor,andhavethepreparationandabilitytoengagein
independentandlife-longlearninginthebroadestcontextoftechnologicalchange.
ProgramSpecific Outcomes
PSO1 Professional Skills: The ability to research, understand and implement computer programs in the areas
relatedtoalgorithms,systemsoftware,multimedia,webdesign,bigdataanalytics,andnetworkingfor
efficientanalysisanddesignofcomputer-basedsystemsofvaryingcomplexity.
PSO2 Problem-SolvingSkills:Theabilitytoapplystandardpracticesandstrategiesinsoftwareproject
developmentusingopen-endedprogrammingenvironmentstodeliveraqualityproductforbusiness
success.
PSO3 SuccessfulCareerandEntrepreneurship:Theabilitytoemploymoderncomputerlanguages,
environments,andplatformsincreatinginnovativecareerpaths,tobeanentrepreneur,andazestfor
higherstudies.
OPERATINGSYSTEMSLABSYLLABUS
(PracticalHours:03,Credits:02)

ImplementthefollowingprogramsonLinuxplatformusingClanguage.

Exp. Division of Page


ListofExperiments
No. Experiments No.
WriteaCprogramtosimulatethefollowingnon-preemptiveCPU scheduling
1 algorithms to find turnaround time and waiting time. 2
a)FCFS b)SJF c)RoundRobin(pre-emptive) d)Priority
CPU
*Write a C program to simulate multi-level queue scheduling algorithm
Scheduling
considering the following scenario.All the processes in the system are
Algorithms
2 divided into two categories – system processes and user processes. 7
Systemprocessesare tobegivenhigherprioritythanuserprocesses.Use
FCFSschedulingfortheprocessesineachqueue.
File
WriteaCprogramtosimulatethefollowingfileallocationstrategies.
3 Allocation 9
a)Sequential b)Indexed c)Linked
Strategies
Write a C program to simulate the MVT and MFT memory management
4 13
techniques.
Memory *WriteaCprogramtosimulatethefollowingcontiguousmemory allocation
5 Management techniques 16
Techniques a)Worst-fit b)Best-fit c)First-fit

6 WriteaCprogramtosimulatepagingtechniqueofmemorymanagement. 20

File
WriteaCprogramtosimulatethefollowingfileorganizationtechniques
7 Organization 22
a)Singleleveldirectory b)Twoleveldirectory c)Hierarchical
Techniques
WriteaCprogramtosimulateBankersalgorithmforthepurposeof deadlock
8 Deadlock 29
avoidance.
Management
Techniques *WriteaCprogramtosimulatediskschedulingalgorithms
9 32
a)FCFS b)SCAN c)C-SCAN
WriteaCprogramtosimulatepagereplacementalgorithms
10 Page 36
a)FIFO b)LRU c)LFU
Replacement
Algorithms *WriteaCprogramtosimulatepagereplacementalgorithms
11 41
a)Optimal
*WriteaCprogramtosimulateproducer-consumerproblemusingsemaphores.
12 Process 44
Synchroniza-
tion *WriteaCprogramtosimulatetheconceptofDining-Philosophers problem.
13 45

14 LabQuestions&Assignments 47

*Contentbeyondtheuniversityprescribedsyllabi
ATTAINMENTOFPROGRAMOUTCOMES
&PROGRAMSPECIFICOUTCOMES

Program
Program
Exp. Specific
Experiment Outcomes
No. Outcomes
Attained
Attained
1 WriteaCprogramtosimulatethefollowingnon-preemptiveCPU scheduling
PO1,PO2,PO4
algorithms to find turnaround time and waiting time. PSO1
a)FCFS b)SJF c)Round Robin d) Priority
2 *Write a C program to simulate multi-level queue scheduling algorithm
considering the following scenario.All the processes in the system are
PO1,PO2,PO3,
divided into two categories – system processes and user processes. PSO1,PSO2
PO4, PO12
Systemprocessesareto begiven higherpriority thanuserprocesses. Use
FCFSschedulingfortheprocessesineachqueue.
3 WriteaCprogramtosimulatethefollowingfileallocationstrategies.
PO1,PO2,PO4 PSO1
a)Sequential b)Indexed c)Linked
4 Write a C program to simulate the MVT and MFT memory management
PO1,PO2,PO4 PSO1
techniques.
5 *WriteaCprogramtosimulatethefollowingcontiguousmemoryallocation
PO1,PO2,PO4,
techniques PSO1
PO12
a)Worst-fit b)Best-fit c)First-fit
6 WriteaCprogramtosimulatepagingtechniqueofmemorymanagement.
PO1,PO2,PO4 PSO1

7 WriteaCprogramtosimulatethefollowingfileorganizationtechniques
PO1,PO2,PO4 PSO1
a)Singleleveldirectory b)Twoleveldirectory c)Hierarchical
8 WriteaCprogramtosimulateBankersalgorithmforthepurposeof deadlock
PO1,PO2,PO4 PSO1
avoidance.
9 *WriteaCprogramtosimulatediskschedulingalgorithms PO1,PO2,PO4,
PSO1
a)FCFS b)SCAN c)C-SCAN PO12
10 WriteaCprogramtosimulatepagereplacementalgorithms
PO1,PO2 PSO1
a)FIFO b)LRU c)LFU
11 *WriteaCprogramtosimulatepagereplacementalgorithms
PO1,PO2, PO12 PSO1
a)Optimal
12 *WriteaCprogramtosimulateproducer-consumerproblemusingsemaphores. PO1,PO2,PO3,
PSO1,PSO2
PO4,PO5,PO12
13 *WriteaCprogramtosimulatetheconceptofDining-Philosophers problem. PO1,PO2,PO3,
PSO1,PSO2
PO4,PO5,PO12

*Contentbeyondtheuniversityprescribedsyllabi
OPERATINGSYSTEMSLABORATORY

OBJECTIVE:

Thislabcomplements theoperatingsystemscourse.Studentswillgainpracticalexperiencewithdesigningand
implementing concepts of operating systems such as system calls, CPU scheduling, process management,
memory management, file systems and deadlock handling using C language in Linux environment.

OUTCOMES:
UponthecompletionofOperatingSystemspracticalcourse,thestudentwillbeableto:

1. Understandandimplementbasic servicesand functionalities of the operatingsystemusing system calls.

2. Usemodernoperatingsystemcallsandsynchronizationlibrariesinsoftware/hardwareinterfaces.

3. Understandthebenefitsofthreadoverprocessandimplementsynchronizedprogramsusing multithreading
concepts.

4. AnalyzeandsimulateCPUSchedulingAlgorithmslikeFCFS,RoundRobin,SJF,andPriority.

5. Implementmemorymanagementschemesandpagereplacementschemes.

6. Simulatefileallocationandorganizationtechniques.

7. Understandtheconceptsofdeadlock inoperatingsystemsandimplementtheminmultiprogramming
system.
EXPERIMENT1

OBJECTIVE
Writea Cprogramto simulatethe followingnon-preemptive CPU scheduling algorithms to find turnaround time
and waiting time for the above problem.
a)FCFS b)SJF c)Round Robin d) Priority

DESCRIPTION
Assumealltheprocessesarriveatthesametime.

FCFSCPUSCHEDULINGALGORITHM
For FCFS scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times. The
scheduling isperformed on thebasisofarrival time oftheprocesses irrespectiveof their otherparameters. Each
process will be executed according to its arrival time. Calculate the waiting time and turnaround time of each of
the processes accordingly.

SJFCPUSCHEDULINGALGORITHM
For SJF scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times. Arrangeall
the jobs in order with respect to their burst times. There may be two jobs in queue with the same execution
time, and then FCFS approach is to be performed. Each process will be executed according to the length of its
burst time. Then calculate the waiting time and turnaround time of each of the processes accordingly.

ROUNDROBINCPUSCHEDULINGALGORITHM
For round robin scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times,
and the size of the time slice. Time slices are assigned to each process in equal portions and in circular order,
handling all processes execution. This allows every process to get an equal chance. Calculate the waiting time
and turnaround time of each of the processes accordingly.

PRIORITYCPUSCHEDULINGALGORITHM
For priority scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times, and
the priorities. Arrange all the jobs in order with respect to their priorities. There may be two jobs in queue with
the same priority, and then FCFS approach is to be performed. Each process will be executed according to its
priority. Calculate the waiting time and turnaround time of each of the processes accordingly.

PROGRAM

FCFSCPUSCHEDULINGALGORITHM
#include<stdio.h>
#include<conio.h>
main()
{
intbt[20],wt[20],tat[20],i,n; float
wtavg, tatavg;
clrscr();
printf("\nEnterthenumberofprocesses--"); scanf("%d",
&n);
for(i=0;i<n;i++)
{
printf("\nEnterBurstTimeforProcess%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("\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
2
for(i=0;i<n;i++)
printf("\n\tP%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("\nAverageTurnaroundTime--%f",tatavg/n);
getch();
}

INPUT
Enterthenumberofprocesses-- 3
EnterBurstTimeforProcess0-- 24
EnterBurstTimeforProcess1-- 3
EnterBurstTimeforProcess2-- 3

OUTPUT
PROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME
P0 24 0 24
P1 3 24 27
P2 3 27 30

AverageWaitingTime-- 17.000000
AverageTurnaroundTime-- 27.000000

SJFCPUSCHEDULINGALGORITHM
#include<stdio.h>
#include<conio.h>
main()
{
intp[20],bt[20],wt[20],tat[20],i,k,n,temp;
float wtavg, tatavg;
clrscr();
printf("\nEnterthenumberofprocesses--"); scanf("%d",
&n);
for(i=0;i<n;i++)
{
p[i]=i;
printf("EnterBurstTimeforProcess%d--",i);
scanf("%d", &bt[i]);

}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;

temp=p[i];
p[i]=p[k];
p[k]=temp;
}
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("\n\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
for(i=0;i<n;i++)
3
printf("\n\tP%d\t\t%d\t\t%d\t\t%d",p[i],bt[i],wt[i],tat[i]);
printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverageTurnaroundTime--%f",tatavg/n);
getch();
}

INPUT
Enterthenumberofprocesses-- 4
EnterBurstTimeforProcess0-- 6
EnterBurstTimeforProcess1-- 8
EnterBurstTimeforProcess2-- 7
EnterBurstTimeforProcess3-- 3

OUTPUT
PROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME
P3 3 0 3
P0 6 3 9
P2 7 9 16
P1 8 16 24
AverageWaitingTime-- 7.000000
AverageTurnaroundTime-- 13.000000

ROUNDROBINCPUSCHEDULINGALGORITHM
#include<stdio.h>
main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
clrscr();
printf("Enterthenoofprocesses--");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("\nEnterBurstTimeforprocess%d--",i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnterthesizeoftimeslice--");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else
{
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]-ct[i];
att+=tat[i];
4
awt+=wa[i];
}
printf("\nTheAverageTurnaroundtimeis--%f",att/n);
printf("\nThe Average Waiting time is -- %f",awt/n);
printf("\n\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
for(i=0;i<n;i++)
printf("\t%d\t%d\t\t%d\t\t%d\n",i+1,ct[i],wa[i],tat[i]);
getch();
}
INPUT
Enterthenoofprocesses –3
Enter Burst Time for process 1 – 24
Enter Burst Time for process 2 -- 3
Enter Burst Time for process 3 -- 3

Enterthesizeoftimeslice–3

OUTPUT
TheAverageTurnaroundtimeis–15.666667
TheAverageWaitingtimeis -- 5.666667

PROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME


1 24 6 30
2 3 4 7
3 3 7 10

PRIORITYCPUSCHEDULINGALGORITHM
#include<stdio.h>
main()
{
intp[20],bt[20],pri[20],wt[20],tat[20],i,k,n,temp;
float wtavg, tatavg;
clrscr();
printf("Enterthenumberofprocesses---");
scanf("%d",&n);

for(i=0;i<n;i++)
{
p[i]=i;
printf("EntertheBurstTime&PriorityofProcess%d ---",i); scanf("%d
%d",&bt[i], &pri[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(pri[i]>pri[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;

temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;

temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;

}
wtavg=wt[0]= 0;
tatavg=tat[0]=bt[0];
5
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("\nPROCESS\t\tPRIORITY\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME");
for(i=0;i<n;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",p[i],pri[i],bt[i],wt[i],tat[i]);

printf("\nAverage Waiting Time is---%f",wtavg/n);


printf("\nAverageTurnaroundTimeis---%f",tatavg/n);
getch();
}

INPUT
Enterthenumberofprocesses-- 5
EntertheBurstTime&PriorityofProcess0 ---10 3
EntertheBurstTime&PriorityofProcess1 ---1 1
EntertheBurstTime&PriorityofProcess2---2 4
EntertheBurstTime&PriorityofProcess3 ---1 5
EntertheBurstTime&PriorityofProcess4 ---5 2

OUTPUT
PROCESS PRIORITY BURSTTIME WAITINGTIME TURNAROUNDTIME
1 1 1 0 1
4 2 5 1 6
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19
Average Waiting Time is---8.200000
AverageTurnaroundTimeis---12.000000

6
EXPERIMENT2

OBJECTIVE
*Write a C program to simulate multi-level queue scheduling algorithm considering the following scenario.All
the processes in the system are divided into two categories – system processes and user processes. System
processes are to be given higher priority than user processes. The priority of each process ranges from 1 to 3.
Use fixed priority scheduling for all the processes.

DESCRIPTION
Multi-level queue scheduling algorithm is used in scenarios where the processes can be classified into groups
based on property like process type, CPU time, IO access, memory size, etc. In a multi-level queue scheduling
algorithm, there will be 'n' number of queues, where 'n' is the number of groups the processes are classifiedinto.
Each queue will be assigned a priority and will have its own scheduling algorithm like round-robin scheduling or
FCFS. For the process in a queue to execute, all the queues of priority higher than it should be empty, meaning
the process in those high priority queues should have completed its execution. In thisscheduling algorithm, once
assigned to a queue, the process will not move to any other queues.

PROGRAM

main()
{
intp[20],bt[20],su[20],wt[20],tat[20],i,k,n,temp; float
wtavg, tatavg;
clrscr();
printf("Enterthenumberofprocesses---");
scanf("%d",&n);

for(i=0;i<n;i++)
{
p[i]=i;
printf("EntertheBurstTimeofProcess%d---",i);
scanf("%d",&bt[i]);
printf("System/UserProcess(0/1)?---");
scanf("%d", &su[i]);

}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(su[i]>su[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;

temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;

temp=su[i];
su[i]=su[k];
su[k]=temp;

}
wtavg=wt[0]= 0;
tatavg=tat[0]=bt[0];

for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=tat[i-1]+bt[i];

7
wtavg = wtavg + wt[i];
tatavg=tatavg+tat[i];
}

printf("\nPROCESS\t\tSYSTEM/USERPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUND TIME");
for(i=0;i<n;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",p[i],su[i],bt[i],wt[i],tat[i]);

printf("\nAverage Waiting Time is---%f",wtavg/n);


printf("\nAverageTurnaroundTimeis---%f",tatavg/n); getch();
}

INPUT
Enter the number of processes---4
EntertheBurstTimeofProcess0 ---3
System/User Process (0/1) ? ---
1EntertheBurstTimeofProcess1---2
System/User Process (0/1) ? ---
0EntertheBurstTimeofProcess2 ---5
System/User Process (0/1) ? ---
1EntertheBurstTimeofProcess3 ---1
System/User Process (0/1) ? --- 0

OUTPUT
PROCESS SYSTEM/USERPROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME
1 0 2 0 2
3 0 1 2 3
2 1 5 3 8
0 1 3 8 11

Average Waiting Time is---3.250000


AverageTurnaroundTimeis---6.000000

8
EXPERIMENT3

OBJECTIVE
WriteaCprogramtosimulatethefollowingfileallocationstrategies.
a)Sequential b)Linked c)) Indexed

DESCRIPTION
A file is a collection of data, usually stored on disk. As a logical entity, a file enables to divide data intomeaningful
groups. As a physical entity, a file should be considered in terms of its organization. The term "file organization"
refers to the way in which data is stored in a file and, consequently, the method(s) by which it can be accessed.

SEQUENTIALFILEALLOCATION
In this file organization, the records of the file are stored one after another both physically and logically. That is,
record with sequence number 16 is located just after the 15th record. A record of a sequential file can only be
accessed by reading all the previous records.

LINKEDFILEALLOCATION
With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered anywhere on the
disk. The directory contains a pointer to the first and last blocks of the file. Each block contains a pointer to the
next block.

INDEXEDFILEALLOCATION
Indexed file allocation strategy brings all the pointers together into one location: an index block. Each file has its
ownindex block, which is an array of disk-block addresses. The ithentry in the index block points to the ith block
ofthefile. Thedirectory containstheaddressoftheindex block. To find and read thei thblock, thepointer in the ith
index-block entry is used.

PROGRAM

SEQUENTIALFILEALLOCATION
#include<stdio.h>
#include<conio.h>

structfileTable
{
charname[20];
int sb, nob;
}ft[30];

voidmain()
{
int i, j, n;
chars[20];
clrscr();
printf("Enter no of files :");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
printf("Enter starting block of file %d :",i+1);
scanf("%d",&ft[i].sb);
printf("Enternoofblocksinfile%d:",i+1);
scanf("%d",&ft[i].nob);
}
printf("\nEnterthefilenametobesearched--");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s,ft[i].name)==0)

9
break;
if(i==n)
printf("\nFileNotFound");
else
{
printf("\nFILENAMESTARTBLOCKNOOFBLOCKSBLOCKSOCCUPIED\n");
printf("\n%s\t\t%d\t\t%d\t",ft[i].name,ft[i].sb,ft[i].nob);
for(j=0;j<ft[i].nob;j++)
printf("%d,",ft[i].sb+j);
}
getch();
}

INPUT:
Enternooffiles:3

Enterfilename1:A
Enterstartingblockoffile1:85
Enter no of blocks in file 1:6

Enterfilename2:B
Enterstartingblockoffile2:102
Enter no of blocks in file 2:4

Enterfilename3:C
Enterstartingblockoffile3:60
Enter no of blocks in file 3:4
Enterthefilenametobesearched--B

OUTPUT:
FILENAME STARTBLOCK NOOFBLOCKS BLOCKSOCCUPIED
B 102 4 102,103,104,105

LINKEDFILEALLOCATION
#include<stdio.h>
#include<conio.h>

structfileTable
{
charname[20];
int nob;
structblock*sb;
}ft[30];

structblock
{
int bno;
structblock*next;
};

voidmain()
{
int i, j, n;
chars[20];
structblock*temp;
clrscr();
printf("Enter no of files :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
10
printf("Enternoofblocksinfile%d:",i+1);
scanf("%d",&ft[i].nob);
ft[i].sb=(structblock*)malloc(sizeof(structblock));
temp = ft[i].sb;
printf("Entertheblocksofthefile:");
scanf("%d",&temp->bno);
temp->next=NULL;

for(j=1;j<ft[i].nob;j++)
{
temp->next=(structblock*)malloc(sizeof(structblock));
temp = temp->next;
scanf("%d",&temp->bno);
}
temp->next=NULL;
}
printf("\nEnterthefilenametobesearched--");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s,ft[i].name)==0)
break;
if(i==n)
printf("\nFileNotFound");
else
{
printf("\nFILENAMENOOFBLOCKSBLOCKSOCCUPIED");
printf("\n%s\t\t%d\t",ft[i].name,ft[i].nob); temp=ft[i].sb;
for(j=0;j<ft[i].nob;j++)
{
printf("%d",temp->bno);
temp = temp->next;
}
}
getch();
}

INPUT:
Enternooffiles 2

Enterfile1:A
Enternoofblocksinfile1 4
Entertheblocksofthefile1 :122394

Enterfile2:G
Enternoofblocksinfile2 5
Enter the blocks of the file 2 8877665544

Enter the file to be searched: G

OUTPUT:
FILENAME NOOFBLOCKS BLOCKSOCCUPIED
G 5 8877665544

INDEXEDFILEALLOCATION
#include<stdio.h>
#include<conio.h>

structfileTable
{
charname[20];
intnob,blocks[30];

11
}ft[30];

voidmain()
{
int i, j, n;
chars[20];
clrscr();
printf("Enter no of files :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
printf("Enternoofblocksinfile%d:",i+1);
scanf("%d",&ft[i].nob);
printf("Entertheblocksofthefile:");
for(j=0;j<ft[i].nob;j++)
scanf("%d",&ft[i].blocks[j]);
}

printf("\nEnterthefilenametobesearched--");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s,ft[i].name)==0)
break;
if(i==n)
printf("\nFileNotFound");
else
{
printf("\nFILENAMENOOFBLOCKSBLOCKSOCCUPIED");
printf("\n%s\t\t%d\t",ft[i].name,ft[i].nob); for(j=0;j<ft[i].nob;j++)
printf("%d,",ft[i].blocks[j]);

}
getch();
}

INPUT:
Enternooffiles 2

Enterfile1:A
Enternoofblocksinfile1 4
Entertheblocksofthefile1 :122394

Enterfile2:G
Enternoofblocksinfile2 5
Enter the blocks of the file 2 8877665544
Enter the file to be searched: G

OUTPUT:
FILENAME NOOFBLOCKS BLOCKSOCCUPIED
G 5 88,77,66,55, 44

12
EXPERIMENT4

OBJECTIVE
WriteaCprogramtosimulatetheMVTandMFTmemorymanagementtechniques

DESCRIPTION
MFT (Multiprogramming with a Fixed number of Tasks) is one of the old memory management techniques in
which the memory is partitioned into fixed size partitions and each job is assigned to a partition. The memory
assigned to a partition does not change. MVT (Multiprogramming with a Variable number of Tasks) is the
memory management technique in which each job gets just the amount of memory it needs. That is, the
partitioning of memory is dynamic and changes as jobs enter and leave the system. MVT is a more ``efficient''
user of resources. MFT suffers with the problem of internal fragmentation and MVT suffers with external
fragmentation.

PROGRAM

MFTMEMORYMANAGEMENTTECHNIQUE
#include<stdio.h>
#include<conio.h>

main()
{
intms,bs,nob,ef,n,mp[10],tif=0; int
i,p=0;

clrscr();
printf("Enterthetotalmemoryavailable(inBytes) --");
scanf("%d",&ms);
printf("Entertheblocksize(inBytes)--");
scanf("%d", &bs);
nob=ms/bs;
ef=ms-nob*bs;
printf("\nEnterthenumberofprocesses--");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Entermemoryrequiredforprocess%d(inBytes)--",i+1);
scanf("%d",&mp[i]);
}

printf("\nNo.ofBlocksavailableinmemory--%d",nob);
printf("\n\nPROCESS\tMEMORYREQUIRED\tALLOCATED\tINTERNALFRAGMENTATION");
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("\nMemoryisFull,RemainingProcessescannotbeaccomodated");

printf("\n\nTotalInternalFragmentationis%d",tif);
printf("\nTotal External Fragmentation is %d",ef);
getch();
13
}

INPUT
Enterthetotalmemoryavailable(inBytes)-- 1000
Entertheblocksize(inBytes)-- 300
Enterthenumberofprocesses–5
Entermemoryrequiredforprocess1(inBytes)-- 275
Entermemoryrequiredforprocess2(inBytes)-- 400
Entermemoryrequiredforprocess3(inBytes)-- 290
Entermemoryrequiredforprocess4(inBytes)-- 293
Entermemoryrequiredforprocess5(inBytes)-- 100

No.ofBlocksavailableinmemory-- 3

OUTPUT
PROCESS MEMORY REQUIRED ALLOCATED INTERNALFRAGMENTATION
1 275 YES 25
2 400 NO -----
3 290 YES 10
4 293 YES 7

MemoryisFull,RemainingProcessescannotbeaccommodated
Total Internal Fragmentation is 42
TotalExternalFragmentationis 100

MVTMEMORYMANAGEMENTTECHNIQUE
#include<stdio.h>
#include<conio.h>

main()
{
intms,mp[10],i,temp,n=0;
char ch = 'y';

clrscr();
printf("\nEnterthetotalmemoryavailable(inBytes)--");
scanf("%d",&ms);
temp=ms;
for(i=0;ch=='y';i++,n++)
{
printf("\nEntermemoryrequiredforprocess%d(inBytes) --",i+1);
scanf("%d",&mp[i]);
if(mp[i]<=temp)
{
printf("\nMemoryisallocatedforProcess%d",i+1); temp =
temp - mp[i];
}
else
{
printf("\nMemoryisFull");
break;
}
printf("\nDoyouwanttocontinue(y/n)--");
scanf(" %c", &ch);
}
printf("\n\nTotalMemoryAvailable--%d",ms);

printf("\n\n\tPROCESS\t\tMEMORYALLOCATED");
for(i=0;i<n;i++)
printf("\n \t%d\t\t%d",i+1,mp[i]);
printf("\n\nTotalMemoryAllocatedis%d",ms-temp);
printf("\nTotal External Fragmentation is %d",temp);
14
getch();
}

INPUT
Enterthetotalmemoryavailable(inBytes)-- 1000

Entermemoryrequiredforprocess1(inBytes)-- 400
MemoryisallocatedforProcess1
Doyouwanttocontinue(y/n)-- y

Entermemoryrequiredforprocess2(inBytes)-- 275
MemoryisallocatedforProcess2
Doyouwanttocontinue(y/n)-- y

Entermemoryrequiredforprocess3(inBytes)-- 550

OUTPUT
MemoryisFull
TotalMemoryAvailable--1000

PROCESS MEMORY ALLOCATED


1 400
2 275

TotalMemoryAllocatedis675
TotalExternalFragmentationis 325

15
EXPERIMENT5

OBJECTIVE
*WriteaCprogramtosimulatethefollowingcontiguousmemoryallocationtechniques
a)Worst-fit b)Best-fit c)First-fit

DESCRIPTION
One of the simplest methods for memory allocation is to divide memory into several fixed-sized partitions. Each
partitionmaycontainexactlyoneprocess.Inthismultiple-partitionmethod,whenapartitionisfree,aprocessis selected
from the input queue and is loaded into the free partition. When the process terminates, the partition becomes
available for another process. The operating system keeps a table indicating which parts of memoryare available
and which are occupied. Finally, when a process arrives and needs memory, a memory sectionlarge enough for
this process is provided. When it is time to load or swap a process into main memory, and if there is more than
one free block of memory of sufficient size, then the operating system must decide whichfree block to allocate.
Best-fit strategy chooses the block that is closest in size to the request. First-fit choosesthe first available block
that is large enough. Worst-fit chooses the largest available block.

PROGRAM

WORST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25

voidmain()
{
intfrag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();

printf("\n\tMemoryManagementScheme-FirstFit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enterthenumberoffiles:");
scanf("%d",&nf);
printf("\nEnterthesizeoftheblocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enterthesizeofthefiles:-\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++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
16
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();
}
INPUT
Enterthenumberofblocks:3 Enter
the number of files: 2

Enterthesizeoftheblocks:-
Block 1: 5
Block2:2
Block3:7

Enterthesizeofthefiles:- File
1: 1
File2:4

OUTPUT
File No FileSize Block No BlockSize Fragment
1 1 1 5 4
2 4 3 7 3

BEST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25

voidmain()
{
intfrag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
clrscr();

printf("\nEnterthenumberofblocks:");
scanf("%d",&nb);
printf("Enterthenumberoffiles:");
scanf("%d",&nf);
printf("\nEnterthesizeoftheblocks:-\n");
for(i=1;i<=nb;i++)
printf("Block%d:",i);scanf("%d",&b[i]);

printf("Enterthesizeofthefiles:-\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++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
17
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFileNo\tFileSize\tBlockNo\tBlockSize\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();
}

INPUT
Enterthenumberofblocks:3 Enter
the number of files: 2

Enterthesizeoftheblocks:-
Block 1: 5
Block2:2
Block3:7

Enterthesizeofthefiles:- File
1: 1
File2:4

OUTPUT
File No FileSize Block No BlockSize Fragment
1 1 2 2 1
2 4 1 5 1

FIRST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25

voidmain()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
clrscr();

printf("\n\tMemoryManagementScheme-WorstFit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enterthenumberoffiles:");
scanf("%d",&nf);
printf("\nEnterthesizeoftheblocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enterthesizeofthefiles:-\n");
for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
18
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)//ifbf[j]isnotallocated
{
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();
}

INPUT
Enterthenumberofblocks:3 Enter
the number of files: 2

Enterthesizeoftheblocks:-
Block 1: 5
Block2:2
Block3:7

Enterthesizeofthefiles:- File
1: 1
File2:4

OUTPUT
File No FileSize Block No BlockSize Fragment
1 1 3 7 6
2 4 1 5 1

19
EXPERIMENT6

OBJECTIVE
WriteaCprogramtosimulatepagingtechniqueofmemorymanagement.

DESCRIPTION
In computeroperating systems, paging is oneofthe memory management schemesby which a computer stores
and retrieves data from the secondary storage for use in main memory. In the paging memory-management
scheme,theoperatingsystemretrievesdatafromsecondarystorageinsame-sizeblockscalledpages.Pagingisa
memory-management schemethat permitsthephysical address spacea processto benoncontiguous. Thebasic
method for implementing paging involves breaking physical memory into fixed-sized blocks called frames and
breaking logical memory into blocks of the same size called pages. When a process is to be executed, its pages
are loaded into any available memory frames from their source.

PROGRAM
#include<stdio.h>
#include<conio.h>

main()
{
intms,ps,nop,np,rempages,i,j,x,y,pa,offset; int
s[10], fno[10][20];

clrscr();

printf("\nEnterthememorysize--");
scanf("%d",&ms);

printf("\nEnterthepagesize--");
scanf("%d",&ps);

nop=ms/ps;
printf("\nTheno.ofpagesavailableinmemoryare --%d",nop);

printf("\nEnternumberofprocesses--"); scanf("%d",&np);

rempages = nop;

for(i=1;i<=np;i++)
{

printf("\nEnterno.ofpagesrequiredforp[%d]--",i);
scanf("%d",&s[i]);

if(s[i]>rempages)
{
printf("\nMemoryisFull");
break;
}
rempages=rempages-s[i];

printf("\nEnterpagetableforp[%d]---",i);
for(j=0;j<s[i];j++)
scanf("%d",&fno[i][j]);
}

printf("\nEnter Logical Address to find Physical Address ");


printf("\nEnterprocessno.andpagenumberandoffset --");

scanf("%d%d%d",&x,&y,&offset);

20
if(x>np||y>=s[i]||offset>=ps)
printf("\nInvalidProcessorPageNumberoroffset");
else
{
pa=fno[x][y]*ps+offset;
printf("\nThePhysicalAddressis--%d",pa);
}
getch();
}

INPUT
Enterthememory size –1000
Enterthepagesize-- 100
Theno.ofpagesavailableinmemoryare--------- 10
Enter number of processes -- 3
Enterno.ofpagesrequiredfor p[1]-- 4
Enterpagetableforp[1]--- 8 6 9 5

Enterno.ofpagesrequiredforp[2]-- 5
Enterpagetableforp[2]--- 1 4 5 7 3

Enterno.ofpagesrequiredforp[3]-- 5

OUTPUT
MemoryisFull

EnterLogicalAddresstofindPhysicalAddress
Enterprocessno.andpagenumberandoffset--2 3 60
ThePhysicalAddressis ------ 760

21
EXPERIMENT7

OBJECTIVE
WriteaCprogramtosimulatethefollowingfileorganizationtechniques
a)Singleleveldirectory b)Twoleveldirectory c)Hierarchical

DESCRIPTION
The directory structure is the organization of files into ahierarchy of folders. In a single-level directory system,all
the files are placed in one directory. There is a root directory which has all files. It has a simple architecture and
there are no sub directories. Advantage of single level directory system is that it is easy to find a file in the
directory. In the two-level directory system, each user has own user file directory (UFD). The system maintains a
master block that has one entry for each user. This master block contains the addresses of the directory of the
users. When a user job starts or a user logsin, the system's master filedirectory (MFD) is searched. When a user
refers to a particular file, only his own UFD is searched. This effectively solves the name collision problem and
isolates users from one another. Hierarchical directory structure allows users to create their own subdirectories
and to organize their files accordingly. A tree is the most common directory structure. The tree has a root
directory, and every file in the system has a unique path name. A directory (or subdirectory) contains a set offiles
or subdirectories.

PROGRAM

SINGLELEVELDIRECTORYORGANIZATION
#include<stdio.h>
struct
{
chardname[10],fname[10][10];
int fcnt;
}dir;

voidmain()
{
int i,ch;
char f[30];
clrscr();
dir.fcnt=0;
printf("\nEnternameofdirectory--");
scanf("%s", dir.dname);
while(1)
{
printf("\n\n1.CreateFile\t2.DeleteFile\t3.SearchFile\n
4.DisplayFiles\t5.Exit\nEnteryourchoice--");
scanf("%d",&ch);
switch(ch)
{
case1:printf("\nEnterthenameofthefile --");
scanf("%s",dir.fname[dir.fcnt]);dir.fcnt++;
break;
case2:printf("\nEnterthenameofthefile --"); scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f,dir.fname[i])==0)
{
printf("File %s is deleted ",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
}
}
if(i==dir.fcnt)
printf("File%snotfound",f);

22
else
dir.fcnt--;
break;

case3:printf("\nEnterthenameofthefile --"); scanf("%s",f);


for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f,dir.fname[i])==0)
{
printf("File%sisfound",f);
break;
}
}
if(i==dir.fcnt)
printf("File%snotfound",f);
break;
case4:if(dir.fcnt==0)
printf("\nDirectoryEmpty");
else
{
printf("\nTheFilesare--"); for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);

}
break;
default:exit(0);
}

}
getch();
}

OUTPUT:
Enternameofdirectory --CSE
1.CreateFile 2.DeleteFile3.SearchFile
4. Display Files 5. Exit Enteryourchoice–1

Enter the name of the file --A

1.CreateFile 2.DeleteFile3.SearchFile
4. Display Files 5. Exit Enteryourchoice–1

Enter the name of the file --B

1.CreateFile 2.DeleteFile3.SearchFile
4.DisplayFiles 5. Exit Enteryourchoice–1

Enterthenameofthefile--C
1.CreateFile 2.DeleteFile3.SearchFile
4. Display Files 5. Exit Enteryourchoice–4

The Files are --A BC

1.CreateFile 2.DeleteFile3.SearchFile
4.DisplayFiles 5. Exit Enteryourchoice–3

Enterthenameofthefile–ABC File
ABC not found

1.CreateFile 2.DeleteFile3.SearchFile
4.DisplayFiles 5. Exit Enteryourchoice–2

23
Enterthenameofthefile–B File
B is deleted

1.CreateFile 2.DeleteFile3.SearchFile
4.DisplayFiles 5. Exit Enteryourchoice–5

TWOLEVELDIRECTORYORGANIZATION
#include<stdio.h>
struct
{
chardname[10],fname[10][10];
int fcnt;
}dir[10];

voidmain()
{
int i,ch,dcnt,k;
charf[30],d[30];
clrscr();
dcnt=0;

while(1)
{
printf("\n\n1.CreateDirectory\t2.CreateFile\t3.DeleteFile");
printf("\n4. Search File\t\t5. Display\t6. Exit\t
Enteryourchoice-- ");
scanf("%d",&ch);
switch(ch)
{
case1:printf("\nEnternameofdirectory--");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directorycreated");
break;
case2:printf("\nEnternameofthedirectory --");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Enternameofthefile--");
scanf("%s",dir[i].fname[dir[i].fcnt]);
dir[i].fcnt++;
printf("Filecreated");
break;
}
if(i==dcnt)
printf("Directory%snotfound",d);
break;
case3:printf("\nEnternameofthedirectory --");
scanf("%s",d);
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enternameofthefile--");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f,dir[i].fname[k])==0)

24
{
printf("File%sisdeleted",f);
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
}
}
printf("File%snotfound",f);
goto jmp;
}
}
printf("Directory%snotfound",d);
jmp: break;

case4:printf("\nEnternameofthedirectory --");
scanf("%s",d);
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enterthenameofthefile--");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f,dir[i].fname[k])==0)
{
printf("File%sisfound",f); goto
jmp1;
}
}
printf("File%snotfound",f);
goto jmp1;
}
}
printf("Directory%snotfound",d);
jmp1:break;
case5:if(dcnt==0)
printf("\nNoDirectory's");
else
{
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
printf("\n%s\t\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
}
}
break;
default:exit(0);
}

}
getch();
}

OUTPUT:
1.CreateDirectory 2.CreateFile 3.DeleteFile
4.SearchFile 5.Display 6. Exit Enteryourchoice-- 1

Enternameofdirectory--DIR1
Directory created
25
1.CreateDirectory 2.CreateFile 3.DeleteFile
4.SearchFile 5.Display 6. Exit Enteryourchoice-- 1
Enternameofdirectory--DIR2
Directory created

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6. Exit Enteryourchoice-- 2

Enternameofthedirectory – DIR1
Enternameofthefile--A1 File
created

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6. Exit Enteryourchoice-- 2

Enternameofthedirectory – DIR1
Enternameofthefile--A2 File
created

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6. Exit Enteryourchoice-- 2

Enternameofthedirectory –DIR2
Enternameofthefile--B1 File
created

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6.Exit Enteryourchoice-- 5

Directory Files
DIR1 A1 A2
DIR2 B1

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6. Exit Enteryourchoice-- 4

Enternameofthedirectory–DIR
Directory not found

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6. Exit Enteryourchoice-- 3

Enternameofthedirectory–DIR1
Enternameofthefile-- A2
FileA2isdeleted

1.CreateDirectory 2.CreateFile 3.DeleteFile


4.SearchFile 5.Display 6. Exit Enteryourchoice-- 6

HIERARCHICALDIRECTORYORGANIZATION
#include<stdio.h>
#include<graphics.h>str
uct tree_element
{
charname[20];
intx,y,ftype,lx,rx,nc,level;
structtree_element*link[5];
};
typedefstructtree_elementnode; void
main()
{
26
intgd=DETECT,gm;
node *root;
root=NULL;
clrscr();
create(&root,0,"root",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\tc\BGI");
display(root);
getch();
closegraph();
}
create(node**root,intlev,char*dname,intlx,intrx,intx)
{
int i, gap;
if(*root==NULL)
{
(*root)=(node*)malloc(sizeof(node));
printf("Enternameofdir/file(under%s):",dname);
fflush(stdin);
gets((*root)->name);
printf("enter1forDir/2forfile:");
scanf("%d",&(*root)->ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
printf("Noofsubdirectories/files(for%s):",(*root)->name);scanf("%d",&(*root)>nc);
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)>link[i]),lev+1,(*root)>name,lx+gap*i,lx+gap*i+gap,
lx+gap*i+gap/2);
}
else
(*root)->nc=0;
}
}
display(node*root)
{
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);if(root
!=NULL)
{
for(i=0;i<root->nc;i++)
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
if(root->ftype==1)
bar3d(root->x-20,root->y-10,root->x+20,root>y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
display(root->link[i]);
27
}
}
INPUT
EnterNameofdir/file(underroot):ROOT
Enter 1 for Dir/2 for File:1
No of subdirectories/files(for ROOT): 2
EnterNameofdir/file(underROOT):USER1
Enter 1 for Dir/2 for File: 1
Noofsubdirectories/files(forUSER1):1
EnterNameofdir/file(underUSER1):SUBDIR1 Enter
1 for Dir/2 for File: 1
No of subdirectories/files(for SUBDIR1): 2
EnterNameofdir/file(underUSER1):JAVA
Enter 1 for Dir/2 for File: 1
No of subdirectories/files(for JAVA): 0
EnterNameofdir/file(underSUBDIR1):VB
Enter 1 for Dir/2 for File: 1
Noofsubdirectories/files(forVB):0
EnterNameofdir/file(underROOT):USER2
Enter 1 for Dir/2 for File: 1
Noofsubdirectories/files(forUSER2):2
Enter Name of dir/file(under ROOT): A
Enter 1 for Dir/2 for File: 2
EnterNameofdir/file(underUSER2):SUBDIR2 Enter
1 for Dir/2 for File: 1
No of subdirectories/files(for SUBDIR2): 2
EnterNameofdir/file(underSUBDIR2):PPL
Enter 1 for Dir/2 for File: 1
Noofsubdirectories/files(forPPL):2
EnterNameofdir/file(underPPL):B
Enter 1 for Dir/2 for File: 2
EnterNameofdir/file(underPPL):C
Enter 1 for Dir/2 for File: 2
EnterNameofdir/file(underSUBDIR):AI
Enter 1 for Dir/2 for File: 1
Noofsubdirectories/files(forAI):2
EnterNameofdir/file(underAI):D
Enter 1 for Dir/2 for File: 2
EnterNameofdir/file(underAI):E
Enter 1 for Dir/2 for File: 2

OUTPUT

ROOT

USER1 USER2

SUBDIR A SUBDIR

JAVA VB PPL AI

B C D E

28
EXPERIMENT8

OBJECTIVE
WriteaCprogramtosimulateBankersalgorithmforthepurposeofdeadlockavoidance.

DESCRIPTION
Inamultiprogrammingenvironment,severalprocessesmay competeforafinitenumberofresources.Aprocess
requests resources; if the resources are not available at that time, the process enters a waiting state.Sometimes,
a waiting process is never again able to change state, because the resources it has requested are held by other
waiting processes. This situation is called a deadlock. Deadlock avoidance is one of the techniques for handling
deadlocks. This approach requires that the operating system be given in advance additional information
concerning which resources a process will request and use during its lifetime. With this additional knowledge, it
can decide for each request whether or not the process should wait. To decide whether the current request can
be satisfied or must be delayed,the system must consider the resourcescurrently available, the resources
currently allocated to each process, and the future requests and releases of each process.Banker’s algorithm is a
deadlock avoidance algorithm that is applicable to a system with multiple instances of each resource type.

PROGRAM
#include<stdio.h>st
ruct file
{
int all[10];
int max[10];
intneed[10];
int flag;
};
voidmain()
{
structfilef[10]; int
fl;
inti,j,k,p,b,n,r,g,cnt=0,id,newr; int
avail[10],seq[10];
clrscr();
printf("Enternumberofprocesses--");
scanf("%d",&n);
printf("Enternumberofresources--");
scanf("%d",&r);
for(i=0;i<n;i++)
{
printf("Enter details for P%d",i);
printf("\nEnterallocation\t--\t");
for(j=0;j<r;j++)
scanf("%d",&f[i].all[j]);
printf("Enter Max\t\t -- \t");
for(j=0;j<r;j++)
scanf("%d",&f[i].max[j]);
f[i].flag=0;
}
printf("\nEnterAvailableResources\t--\t");
for(i=0;i<r;i++)
scanf("%d",&avail[i]);

printf("\nEnterNewRequestDetails--");
printf("\nEnter pid \t -- \t");
scanf("%d",&id);
printf("EnterRequestforResources\t--\t");
for(i=0;i<r;i++)
{
scanf("%d",&newr);
f[id].all[i]+=newr;

29
avail[i]=avail[i]-newr;
}

for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
f[i].need[j]=f[i].max[j]-f[i].all[j];
if(f[i].need[j]<0)
f[i].need[j]=0;
}
}
cnt=0;
fl=0;
while(cnt!=n)
{
g=0;
for(j=0;j<n;j++)
{
if(f[j].flag==0)
{
b=0;
for(p=0;p<r;p++)
{
if(avail[p]>=f[j].need[p])
b=b+1;
else
b=b-1;
}
if(b==r)
{
printf("\nP%disvisited",j);
seq[fl++]=j;
f[j].flag=1;
for(k=0;k<r;k++)
avail[k]=avail[k]+f[j].all[k];
cnt=cnt+1;
printf("(");
for(k=0;k<r;k++)
printf("%3d",avail[k]);
printf(")");
g=1;
}
}
}
if(g==0)
{
printf("\nREQUESTNOTGRANTED--DEADLOCKOCCURRED");
printf("\n SYSTEM IS IN UNSAFE STATE");
gotoy;
}
}
printf("\nSYSTEMISINSAFESTATE");
printf("\nTheSafeSequenceis--(");
for(i=0;i<fl;i++)
printf("P%d",seq[i]);
printf(")");
y:printf("\nProcess\t\tAllocation\t\tMax\t\t\tNeed\n");
for(i=0;i<n;i++)
{
printf("P%d\t",i);
for(j=0;j<r;j++)
30
printf("%6d",f[i].all[j]);
for(j=0;j<r;j++)
printf("%6d",f[i].max[j]);
for(j=0;j<r;j++)
printf("%6d",f[i].need[j]);
printf("\n");
}
getch();
}

INPUT
Enternumberofprocesses – 5
Enternumberofresources -- 3
Enterdetailsfor P0
Enterallocation -- 0 1 0
EnterMax -- 7 5 3

Enterdetailsfor P1
Enterallocation -- 2 0 0
EnterMax -- 3 2 2

Enterdetailsfor P2
Enterallocation -- 3 0 2
EnterMax -- 9 0 2

Enterdetailsfor P3
Enterallocation -- 2 1 1
EnterMax -- 2 2 2

Enterdetailsfor P4
Enterallocation -- 0 0 2
EnterMax -- 4 3 3

EnterAvailableResources-- 3 3 2
EnterNewRequestDetails--
Enterpid -- 1
EnterRequestforResources -- 1 0 2

OUTPUT
P1isvisited(532)
P3isvisited(743)
P4isvisited(745)
P0isvisited(755)
P2 is visited( 1057)
SYSTEMISINSAFESTATE
TheSafeSequenceis--(P1P3P4P0P2)

Process Allocation Max Need


P0 0 1 0 7 5 3 7 4 3
P1 3 0 2 3 2 2 0 2 0
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1

31
EXPERIMENT9

OBJECTIVE
*WriteaCprogramtosimulatediskschedulingalgorithms
a)FCFS b)SCAN c)C-SCAN

DESCRIPTION
Oneoftheresponsibilitiesoftheoperatingsystemistousethehardwareefficiently. For thediskdrives,meeting this
responsibility entails having fast access time and large disk bandwidth. Both the access time and the
bandwidthcanbeimprovedbymanagingtheorderin whichdiskI/Orequestsare servicedwhichiscalledasdisk
scheduling. The simplest form of disk scheduling is, of course, the first-come, first-served (FCFS) algorithm. This
algorithmisintrinsically fair, but it generally doesnot providethefastest service. In theSCAN algorithm, thedisk
arm starts at one end, and moves towards the other end, servicing requests as it reaches each cylinder, until it
gets to the other end of the disk. At the other end, the direction of head movement is reversed, and servicing
continues. The head continuously scans back and forth across the disk. C-SCAN is a variant of SCAN designed to
provide a more uniform wait time. Like SCAN, C-SCAN moves the head from one end of the disk to the other,
servicing requests along the way. When the head reaches the other end, however, it immediately returns to the
beginning of the disk without servicing any requests on the return trip

PROGRAM

FCFSDISKSCHEDULINGALGORITHM
#include<stdio.h>
main()
{
intt[20],n,I,j,tohm[20],tot=0; float
avhm;
clrscr();
printf(“entertheno.oftracks”);
scanf(“%d”,&n);
printf(“enterthetrackstobetraversed”); for(i=2;i<n+2;i++)
scanf(“%d”,&t*i+);
for(i=1;i<n+1;i++)
{
tohm[i]=t[i+1]-t[i];
if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
}
for(i=1;i<n+1;i++)
tot+=tohm[i];
avhm=(float)tot/n;
printf(“Trackstraversed\tDifferencebetweentracks\n”);
for(i=1;i<n+1;i++)
printf(“%d\t\t\t%d\n”,t*i+,tohm*i+);
printf("\nAverageheadermovements:%f",avhm);
getch();
}

INPUT
Enterno.oftracks:9
Entertrackposition:55 58 60 70 18 90 150 160 184

OUTPUT
Trackstraversed Differencebetweentracks
55 45
58 3
60 2
70 10
18 52
90 72

32
150 60
160 10
184 24

Averageheadermovements:30.888889

SCANDISKSCHEDULINGALGORITHM
#include<stdio.h>
main()
{
intt[20],d[20],h,i,j,n,temp,k,atr[20],tot,p,sum=0;

clrscr();
printf("enterthenooftrackstobetraveresed");
scanf("%d'",&n);
printf("enterthepositionofhead");
scanf("%d",&h);
t[0]=0;t[1]=h;
printf("enterthetracks");
for(i=2;i<n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<n+2;i++)
{
for(j=0;j<(n+2)-i-1;j++)
{ if(t[j]>t[j+1])
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}}}
for(i=0;i<n+2;i++)
if(t[i]==h)
j=i;k=i;
p=0;
while(t[j]!=0)
{
atr[p]=t[j];
j--;
p++;
}
atr[p]=t[j];
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("\nAverageheadermovements:%f",(float)sum/n);
getch();
}

INPUT
Enterno.oftracks:9
Entertrackposition:55 58 60 70 18 90 150 160 184

OUTPUT
Trackstraversed Differencebetweentracks
150 50
33
160 10
184 24
90 94
70 20
60 10
58 2
55 3
18 37

Averageheadermovements:27.77

9.3.3 C-SCANDISKSCHEDULINGALGORITHM
#include<stdio.h>
main()
{
intt[20],d[20],h,i,j,n,temp,k,atr[20],tot,p,sum=0; clrscr();
printf("enterthenooftrackstobetraveresed");
scanf("%d'",&n);
printf("enterthepositionofhead");
scanf("%d",&h);
t[0]=0;t[1]=h;
printf("entertotaltracks");
scanf("%d",&tot);
t[2]=tot-1;
printf("enterthetracks");
for(i=3;i<=n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<=n+2;i++)
for(j=0;j<=(n+2)-i-1;j++)
if(t[j]>t[j+1])
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}
for(i=0;i<=n+2;i++)
if(t[i]==h)
j=i;break;
p=0;
while(t[j]!=tot-1)
{
atr[p]=t[j];
j++;
p++;
}
atr[p]=t[j];
p++;
i=0;
while(p!=(n+3)&&t[i]!=t[h])
{
atr[p]=t[i];
i++;
p++;
}
for(j=0;j<n+2;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];

34
}
printf("totalheadermovements%d",sum);
printf("avg is %f",(float)sum/n);
getch();
}

INPUT
Enterthetrackposition:55 58 60 70 18 90 150 160 184
Enterstartingposition:100

OUTPUT
Trackstraversed DifferenceBetweentracks
150 50
160 10
184 24
18 240
55 37
58 3
60 2
70 10
90 20
Averageseektime:35.7777779

35
EXPERIMENT10

OBJECTIVE
WriteaCprogramtosimulatepagereplacementalgorithms
a)FIFO b)LRU c)LFU

DESCRIPTION
Page replacement is basic to demand paging. It completes the separation between logical memory and physical
memory. With this mechanism, an enormous virtual memory can be provided for programmers on a smaller
physical memory. There are many different page-replacement algorithms. Every operating system probably has
its own replacement scheme. A FIFO replacement algorithm associates with each page the time when that page
was brought into memory. When a page must be replaced, the oldest page is chosen. If the recent past is usedas
an approximation of the near future, then the page that has not been used for the longest period of time can be
replaced. This approach is the Least Recently Used (LRU) algorithm. LRU replacement associates with each page
the time of that page's last use. When a page must be replaced, LRU chooses the page that has not been used
for the longest period of time. Least frequently used (LFU) page-replacement algorithm requires that the page
with the smallest count be replaced. The reason for this selection is that an actively usedpage should have a
large reference count.

PROGRAM

FIFOPAGEREPLACEMENTALGORITHM
#include<stdio.h>
#include<conio.h>
main()
{
inti,j,k,f,pf=0,count=0,rs[25],m[10],n; clrscr();
printf("\nEnterthelengthofreferencestring--");
scanf("%d",&n);
printf("\nEnterthereferencestring--");
for(i=0;i<n;i++)
scanf("%d",&rs[i]);
printf("\nEnterno.offrames--");
scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;

printf("\nThePageReplacementProcessis--\n");
for(i=0;i<n;i++)
{
for(k=0;k<f;k++)
{
if(m[k]==rs[i])
break;
}
if(k==f)
{
m[count++]=rs[i];
pf++;
}
for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPFNo.%d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\nThenumberofPageFaultsusingFIFOare%d",pf); getch();

36
}

INPUT
Enterthelengthofreferencestring –20
Enterthereferencestring-- 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 Enter
no. of frames -- 3

OUTPUT
ThePageReplacementProcessis–
7 -1 -1 PFNo.1
7 0 -1 PFNo.2
7 0 1 PFNo.3
2 0 1 PFNo.4
2 0 1
2 3 1 PFNo.5
2 3 0 PFNo.6
4 3 0 PFNo.7
4 2 0 PFNo.8
4 2 3 PFNo.9
0 2 3 PFNo.10
0 2 3
0 2 3
0 1 3 PFNo.11
0 1 2 PFNo.12
0 1 2
0 1 2
7 1 2 PFNo.13
7 0 2 PFNo.14
7 0 1 PFNo.15

ThenumberofPageFaultsusingFIFOare 15

LRUPAGEREPLACEMENTALGORITHM
#include<stdio.h>
#include<conio.h>
main()
{
inti,j,k,min,rs[25],m[10],count[10],flag[25],n,f,pf=0,next=1; clrscr();
printf("Enterthelengthofreferencestring --");
scanf("%d",&n);
printf("Enterthereferencestring--");
for(i=0;i<n;i++)
{
scanf("%d",&rs[i]);
flag[i]=0;
}
printf("Enterthenumberofframes--");
scanf("%d",&f);
for(i=0;i<f;i++)
{
count[i]=0;
m[i]=-1;
}
printf("\nThePageReplacementprocessis--\n");
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;

37
count[j]=next;
next++;
}

}
if(flag[i]==0)
{
if(i<f)
{
m[i]=rs[i];
count[i]=next;
next++;
}
else
{
min=0;
for(j=1;j<f;j++)
if(count[min]>count[j]) min=j;

m[min]=rs[i];
count[min]=next;
next++;

}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t",m[j]);
if(flag[i]==0)
printf("PFNo.--%d",pf);
printf("\n");
}
printf("\nThenumberofpagefaultsusingLRUare%d",pf);
getch();
}

INPUT
Enterthelengthofreferencestring--20
Enterthereferencestring --7 0120304230321201 701 Enter the
number of frames --3

OUTPUT
ThePageReplacementprocessis--
7 -1 -1 PFNo. --1
7 0 -1 PFNo.--2
7 0 1 PFNo. --3
2 0 1 PFNo. --4
2 0 1
2 0 3 PFNo. --5
2 0 3
4 0 3 PFNo. --6
4 0 2 PFNo. --7
4 3 2 PFNo.--8
0 3 2 PFNo. --9
0 3 2
0 3 2
1 3 2 PFNo. --10
1 3 2
1 0 2 PFNo. --11
1 0 2
1 0 7 PFNo. --12
1 0 7
38
1 0 7
ThenumberofpagefaultsusingLRUare12

LFUPAGEREPLACEMENTALGORITHM
#include<stdio.h>
#include<conio.h>

main()
{
intrs[50],i,j,k,m,f,cntr[20],a[20],min,pf=0; clrscr();
printf("\nEnternumberofpagereferences--");
scanf("%d",&m);

printf("\nEnterthereferencestring--");
for(i=0;i<m;i++)
scanf("%d",&rs[i]);

printf("\nEntertheavailableno.offrames--");
scanf("%d",&f);

for(i=0;i<f;i++)
{
cntr[i]=0;
a[i]=-1;
}
Printf(“\nThePageReplacementProcessis–\n“);
for(i=0;i<m;i++)
{

for(j=0;j<f;j++)
if(rs[i]==a[j])
{
cntr[j]++;
break;
}
if(j==f)
{
min=0;
for(k=1;k<f;k++)
if(cntr[k]<cntr[min])
min=k;
a[min]=rs[i];
cntr[min]=1;
pf++;
}
printf("\n");
for(j=0;j<f;j++)
printf("\t%d",a[j]);
if(j==f)
printf(“\tPFNo.%d”,pf);
}
printf("\n\nTotalnumberofpagefaults--%d",pf); getch();
}

INPUT
Enternumberofpagereferences--10
Enter the reference string -- 123452525143 Enter
the available no. of frames --3

39
OUTPUT
ThePageReplacementProcessis–

1 -1 -1 PFNo.1
1 2 -1 PFNo.2
1 2 3 PFNo.3
4 2 3 PFNo.4
5 2 3 PFNo.5
5 2 3
5 2 3
5 2 1 PFNo.6
5 2 4 PFNo.7
5 2 3 PFNo.8

Totalnumberofpagefaults-- 8

40
EXPERIMENT11

OBJECTIVE
*WriteaCprogramtosimulatepagereplacementalgorithms
a)Optimal

DESCRIPTION
Optimal page replacement algorithm has the lowest page-fault rate of all algorithms and will never suffer from
Belady's anomaly. The basic idea is to replace the page that will not be used for the longest period of time. Use
of this page-replacement algorithm guarantees the lowest possible page fault rate for a fixed number of frames.
Unfortunately, the optimal page-replacement algorithm is difficult to implement, because it requires future
knowledge of the reference string.

PROGRAM
#include<stdio.h>in
t n;
main()
{
int seq[30],fr[5],pos[5],find,flag,max,i,j,m,k,t,s;
int count=1,pf=0,p=0;
floatpfr;
clrscr();
printf("Entermaximumlimitofthesequence:");
scanf("%d",&max);
printf("\nEnterthesequence:");
for(i=0;i<max;i++)
scanf("%d",&seq[i]);
printf("\nEnterno.offrames:");
scanf("%d",&n);
fr[0]=seq[0];
pf++;
printf("%d\t",fr[0]);
i=1;
while(count<n)
{
flag=1;
p++;
for(j=0;j<i;j++)
{
if(seq[i]==seq[j])
flag=0;
}
if(flag!=0)
{
fr[count]=seq[i];
printf("%d\t",fr[count]);
count++;
pf++;
}
i++;
}
printf("\n");
for(i=p;i<max;i++)
{
flag=1;
for(j=0;j<n;j++)
{
if(seq[i]==fr[j])
flag=0;
}
if(flag!=0)
41
{
for(j=0;j<n;j++)
{
m=fr[j];
for(k=i;k<max;k++)
{
if(seq[k]==m)
{
pos[j]=k;
break;
}
else
pos[j]=1;
}
}
for(k=0;k<n;k++)
{
if(pos[k]==1)
flag=0;
}
if(flag!=0)
s=findmax(pos);
if(flag==0)
{
for(k=0;k<n;k++)
{
if(pos[k]==1)
{
s=k;
break;
}
}
}
fr[s]=seq[i];
for(k=0;k<n;k++)
printf("%d\t",fr[k]);
pf++;
printf("\n");
}
}
pfr=(float)pf/(float)max;
printf("\nTheno.ofpagefaultsare%d",pf);
printf("\nPage fault rate %f",pfr);
getch();
}
intfindmax(inta[])
{
int max,i,k=0;
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
{
max=a[i];
k=i;
}
}
returnk;
}
INPUT
Enternumberofpagereferences--10
Enterthereferencestring-- 123452525143
42
Entertheavailableno.offrames--3

OUTPUT
ThePageReplacementProcessis–

1 -1 -1 PFNo.1
1 2 -1 PFNo.2
1 2 3 PFNo.3
4 2 3 PFNo.4
5 2 3 PFNo.5
5 2 3
5 2 3
5 2 1 PFNo.6
5 2 4 PFNo.7
5 2 3 PFNo.8

Totalnumberofpagefaults-- 8

43
www.alljntuworld.in JNTUWorld

EXPERIMENT12
12.1 OBJECTIVE
*WriteaCprogramtosimulateproducer-consumerproblemusingsemaphores.

DESCRIPTION
Producer-consumer problem, is a common paradigm for cooperating processes. A producer process produces
information that is consumed by a consumer process. One solution to the producer-consumer problem uses
shared memory. To allow producer and consumer processes to run concurrently, there must be available a
buffer of items that can be filled by the producer and emptied by the consumer. This buffer will reside in aregion
of memory that is shared by the producer and consumer processes. A producer can produce one item while the
consumer is consuming another item. The producer and consumer must be synchronized, so that the consumer
does not try to consume an item that has not yet been produced.

PROGRAM
#include<stdio.h>v
oid main()
{
intbuffer[10],bufsize,in,out,produce,consume,choice=0; in
= 0;
out=0;
bufsize=10;
while(choice!=3)
{
printf(“\n1.Produce\t2.Consume\t3.Exit”);
printf(“\nEnter your choice:”);
scanf(“%d”,&choice);
switch(choice) {
case1:if((in+1)%bufsize==out)
printf(“\nBufferisFull”);
else
{
printf(“\nEnterthevalue:“);
scanf(“%d”, &produce);
buffer[in] = produce;
in=(in+1)%bufsize;
}
Break;
case2:if(in==out)
printf(“\nBufferisEmpty”);
else
{
consume=buffer[out];
printf(“\nTheconsumedvalueis%d”,consume); out
= (out+1)%bufsize;
}
break;
} } }

OUTPUT
1. Produce 2. Consume 3.Exit
Enter your choice: 2
BufferisEmpty
1. Produce 2. Consume 3.Exit
Enter your choice: 1
Enterthevalue:100
1. Produce 2. Consume 3.Exit
Enter your choice: 2
Theconsumedvalueis100
1. Produce 2. Consume 3.Exit
Enter your choice: 3
44
www.alljntuworld.in JNTUWorld

EXPERIMENT13

OBJECTIVE
*WriteaCprogramtosimulatetheconceptofDining-Philosophersproblem.

DESCRIPTION
The dining-philosophers problem is considered a classic synchronization problem because it is an example of a
large class of concurrency-control problems. It is a simple representation of the need to allocate several
resources among several processes in a deadlock-free and starvation-free manner. Consider five philosophers
whospend theirlivesthinkingandeating.The philosopherssharea circular tablesurrounded byfivechairs, each
belonging to one philosopher. In the center of the table is a bowl of rice, and the table is laid with five single
chopsticks. When a philosopher thinks, she does not interact with her colleagues. From time to time, a
philosopher gets hungry and tries to pick up the two chopsticks that are closest to her (the chopsticks that are
between her and her left and right neighbors). A philosopher may pick up only one chopstick at a time.
Obviously, she cam1ot pick up a chopstick that is already in the hand of a neighbor. When a hungry philosopher
hasbothher chopsticksat thesametime, sheeatswithout releasingherchopsticks.When sheisfinished eating, she
puts down both of her chopsticks and starts thinking again. The dining-philosophers problem may lead to a
deadlock situation and hence some rules have to be framed to avoid the occurrence of deadlock.

PROGRAM
inttph,philname[20],status[20],howhung,hu[20],cho; main()
{
int i;
clrscr();
printf("\n\nDININGPHILOSOPHERPROBLEM");
printf("\nEnterthetotalno.ofphilosophers:");
scanf("%d",&tph);
for(i=0;i<tph;i++)
{
philname[i]=(i+1);
status[i]=1;
}
printf("Howmanyarehungry:");
scanf("%d", &howhung);
if(howhung==tph)
{
printf("\nAllarehungry..\nDeadlockstagewilloccur");
printf("\nExiting..");
}
else
{
for(i=0;i<howhung;i++)
{
printf("Enterphilosopher%dposition:",(i+1)); scanf("%d",
&hu[i]);
status[hu[i]]=2;
}
do
{
printf("1.Onecaneatatatime\t2.Twocaneatatatime\t3.Exit\nEnteryourchoice:");
scanf("%d", &cho);
switch(cho)
{
case1:one();
break;
case2:two();
break;
case3:exit(0);
default:printf("\nInvalidoption..");
}

45
www.alljntuworld.in JNTUWorld

}while(1);
}
}
one()
{
intpos=0,x,i;
printf("\nAllowonephilosophertoeatatanytime\n");
for(i=0;i<howhung; i++, pos++)
{
printf("\nP%disgrantedtoeat",philname[hu[pos]]); for(x=pos;x<howhung;x++)
printf("\nP%diswaiting",philname[hu[x]]);

}
}
two()
{
inti,j,s=0,t,r,x;
printf("\nAllowtwophilosopherstoeatatsametime\n");
for(i=0;i<howhung;i++)
{
for(j=i+1;j<howhung;j++)
{
if(abs(hu[i]-hu[j])>=1&&abs(hu[i]-hu[j])!=4)
{
printf("\n\ncombination%d\n",(s+1));
t=hu[i];
r=hu[j];
s++;
printf("\nP%dandP%daregrantedtoeat",philname[hu[i]],
philname[hu[j]]);
for(x=0;x<howhung;x++)
{
if((hu[x]!=t)&&(hu[x]!=r))
printf("\nP%diswaiting",philname[hu[x]]);
}
}
}
}
}

INPUT
DININGPHILOSOPHERPROBLEM
Enterthetotalno.ofphilosophers:5
How many are hungry : 3
Enterphilosopher1position:2
Enterphilosopher2position:4
Enterphilosopher3position:5

OUTPUT
1.One can eat at a time 2.Two can eat at a time 3.Exit
Enter your choice: 1

Allowonephilosophertoeatatanytime P 3
is granted to eat
P3iswaiting
P5iswaiting
P0iswaiting
P5isgrantedtoeat P
5 is waiting
P0iswaiting
P0isgrantedtoeat P
0 is waiting
46
www.alljntuworld.in JNTUWorld

1.One can eat at a time 2.Two can eat at a time 3.Exit


Enter your choice: 2

Allowtwophilosopherstoeatatsametime combination
1
P3andP5aregrantedtoeat P 0
is waiting

combination2
P3andP0aregrantedtoeat P 5
is waiting

combination3
P5andP0aregrantedtoeat P 3
is waiting

1.One can eat at a time 2.Two can eat at a time 3.Exit


Enter your choice: 3

47
www.alljntuworld.in JNTUWorld

LAB QUESTIONS & ASSIGNMENTS

48
www.alljntuworld.in JNTUWorld

EXPERIMENT1

PRE-LABQUESTIONS
1. Defineoperatingsystem?
2. Whatarethedifferenttypesofoperatingsystems?
3. Defineaprocess?
4. WhatisCPUScheduling?
5. Definearrivaltime,bursttime,waitingtime,turnaroundtime?

POST-LABQUESTIONS
1. WhatistheadvantageofroundrobinCPUschedulingalgorithm?
2. WhichCPUschedulingalgorithmisforreal-timeoperatingsystem?
3. Ingeneral,whichCPUschedulingalgorithmworkswithhighestwaitingtime?
4. IsitpossibletouseoptimalCPUschedulingalgorithminpractice?
5. WhatistherealdifficultywiththeSJFCPUschedulingalgorithm?

ASSIGNMENTQUESTIONS
1. Write a C program to implement round robin CPU scheduling algorithm for the following given scenario. All
the processes in the system are divided into two categories – system processes and user processes. System
processes are to be given higher priority than user processes. Consider the time quantum size for thesystem
processes and user processes to be 5 msec and 2 msec respectively.
2. WriteaCprogramtosimulatepre-emptiveSJFCPUschedulingalgorithm.

EXPERIMENT2

PRE-LAB QUESTIONS
1. Whatismulti-levelqueueCPUScheduling?
2. DifferentiatebetweenthegeneralCPUschedulingalgorithmslikeFCFS,SJFetcandmulti-levelqueueCPU
Scheduling?
3. WhatareCPU-boundI/O-boundprocesses?

POST-LABQUESTIONS
1. Whataretheparameterstobeconsideredfordesigningamultilevelfeedbackqueuescheduler?
2. Differentiatemulti-levelqueueandmulti-levelfeedbackqueueCPUschedulingalgorithms?
3. Whataretheadvantagesofmulti-levelqueueandmulti-levelfeedbackqueueCPUschedulingalgorithms?

ASSIGNMENTQUESTIONS
1. Write a C program to simulate multi-level queue scheduling algorithm considering the following scenario.All
the processes in the system are divided into two categories – system processes and user processes. System
processes are to be given higher priority than user processes. Consider each process priority to be from 1 to
3. Use priority scheduling for the processes in each queue.

EXPERIMENT3

PRE-LABQUESTIONS
1. Definefile?
2. Whatarethedifferentkindsoffiles?
3. Whatisthepurposeoffileallocationstrategies?

POST-LABQUESTIONS
1. Identifyidealscenarioswheresequential,indexedandlinkedfileallocationstrategiesaremostappropriate?
2. Whatarethedisadvantagesofsequentialfileallocationstrategy?
3. Whatisanindexblock?
4. WhatisthefileallocationstrategyusedinUNIX?

49
www.alljntuworld.in JNTUWorld

ASSIGNMENTQUESTIONS
1. WriteaCprogramtosimulateatwo-levelindexschemeforfileallocation?

EXPERIMENT4

PRE-LABQUESTIONS
1. Whatisthepurposeofmemorymanagement unit?
2. Differentiatebetweenlogicaladdressandphysicaladdress?
3. Whatarethedifferenttypesofaddressbindingtechniques?
4. Whatisthebasicideabehindcontiguousmemoryallocation?
5. Howisdynamicmemoryallocationusefulinmultiprogrammingoperatingsystems?

POST-LABQUESTIONS
1. DifferentiatebetweenequalsizedandunequalsizedMFTschemes?
2. WhatistheadvantageofMVTmemorymanagementschemeoverMFT?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtosimulateMFTmemorymanagementschemewithunequalsizedpartitions.

EXPERIMENT5

PRE-LABQUESTIONS
1. DifferentiatebetweenthememorymanagementschemesMFTandMVT?
2. Whatisdynamicmemoryallocation?
3. Whatisexternalfragmentation?

POST-LABQUESTIONS
1. Whichofthedynamiccontiguousmemoryallocationstrategiessufferwithexternalfragmentation?
2. Whatarethepossiblesolutionsfortheproblemofexternalfragmentation?
3. Whatis50-percentrule?
4. Whatiscompaction?
5. Whichofthememoryallocationtechniquesfirst-fit,best-fit,worst-fitisefficient?Why?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtoimplementcompactiontechnique.

EXPERIMENT6

PRE-LABQUESTIONS
1. Whataretheadvantagesofnoncontiguousmemoryallocationschemes?
2. Whatistheprocessofmappingalogicaladdresstophysicaladdresswithrespecttothepagingmemory
management technique?
3. Definetheterms–baseaddress,offset?

POST-LABQUESTIONS
1. Differentiatebetweenpagingandsegmentationmemoryallocationtechniques?
2. Whatisthepurposeofpagetable?
3. Whetherthepagingmemorymanagementtechniquesufferswithinternalorexternalfragmentation
problem. Why?
4. Whatistheeffectofpagingontheoverallcontext-switchingtime?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtosimulatetwo-levelpagingtechnique.
2. WriteaCprogramtosimulatesegmentationmemorymanagementtechnique.

50
www.alljntuworld.in JNTUWorld

EXPERIMENT7

PRE-LABQUESTIONS
1. Definedirectory?
2. Describethegeneraldirectorystructure?
3. Listthedifferenttypesofdirectorystructures?

POST-LABQUESTIONS
1. Whichofthedirectorystructuresisefficient?Why?
2. Whichdirectorystructuredoesnotprovideuser-levelisolationandprotection?
3. Whatistheadvantageofhierarchicaldirectorystructure?

ASSI7GNMENTQUESTIONS
1. WriteaCtosimulateacyclicgraphdirectorystructure?
2. WriteaCtosimulategeneralgraphdirectorystructure?

EXPERIMENT8

PRE-LABQUESTIONS
1. Defineresource.Giveexamples.
2. Whatisdeadlock?
3. Whataretheconditionstobesatisfiedforthedeadlockto occur?

POST-LABQUESTIONS
1. Howcanbetheresourceallocationgraphusedtoidentifyadeadlocksituation?
2. HowisBanker’salgorithmusefuloverresourceallocationgraphtechnique?
3. Differentiatebetweendeadlockavoidanceanddeadlockprevention?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtoimplementdeadlockdetectiontechniqueforthefollowingscenarios?
a. Singleinstanceofeachresourcetype
b. Multipleinstancesofeachresourcetype

EXPERIMENT9

PRE-LABQUESTIONS
1. Whatisdiskscheduling?
2. Listthedifferentdiskschedulingalgorithms?
3. Definetheterms–diskseektime,diskaccesstimeandrotationallatency?

POST-LABQUESTIONS
1. WhatistheadvantageofC-SCANalgorithmoverSCANalgorithm?
2. Whichdiskschedulingalgorithmhashighestrotationallatency?Why?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtoimplementSSTFdiskschedulingalgorithm?

EXPERIMENT10

PRE-LABQUESTIONS
1. Definetheconceptofvirtualmemory?
2. Whatisthepurposeofpagereplacement?
3. Definethegeneralprocessofpagereplacement?
4. Listoutthevariouspagereplacement techniques?
5. Whatispagefault?

POST-LABQUESTIONS
51
www.alljntuworld.in JNTUWorld

1. WhichpagereplacementalgorithmsufferswiththeproblemofBelady’sanomaly?
2. Definetheconceptofthrashing?Whatisthescenariothatleadstothesituationofthrashing?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtosimulateLRU-approximationpagereplacementalgorithm?
a. Additional-Referencebitsalgorithm
b. Second-chancealgorithm

EXPERIMENT11

PRE-LABQUESTIONS
1. Whatarethebenefitsofoptimalpagereplacementalgorithmoverotherpage replacementalgorithms?

POST-LABQUESTIONS
1. Whycan’ttheoptimalpagereplacementtechniquebeusedinpractice?

EXPERIMENT12

PRE-LABQUESTIONS
1. Whatistheneedforprocesssynchronization?
2. Defineasemaphore?
3. Defineproducer-consumerproblem?

POST-LABQUESTIONS
1. Discusstheconsequencesofconsideringboundedandunboundedbuffersinproducer-consumerproblem?
2. Canproducerandconsumerprocessesaccessthesharedmemoryconcurrently?Ifnotwhichtechnique
provides such a benefit?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtosimulateproducer-consumerproblemusingmessage-passingsystem.

EXPERIMENT13

PRE-LABQUESTIONS
1. Differentiatebetweenamonitor,semaphoreandabinarysemaphore?
2. Defineclearlythedining-philosophersproblem?

POST-LABQUESTIONS
1. Identifythescenariosinthedining-philosophersproblemthatleadstothedeadlocksituations?

ASSIGNMENTQUESTIONS
1. WriteaCprogramtosimulatereaders-writersproblemusingmonitors?

52

You might also like