OPERATING SYSTEMS These notes have been prepared mainly from the following books:- (1) Ope ratin g syste m Conce pts By ilberschat!" galvin " gagne #alvin" $indly refer above book for more details% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 'age no%'rocesses Process:- process is a program in e*ec+tion program by itself is not a process: a program is a passive entity" where as a process is an active entity" whereas a process is an active entity% process incl+des the following:- (i) T e st section :- ,t contains the program code (ii) C+rrent ctivity:- ,t is represented by the val+e of the program co+nter and the contents of the processors registers% (iii) tock:- Contains temporary data s+ch as f+nction parameters" ret+rn addresses" and local variables% (iv) ata ection:- Contains global variables% (v) .eap:- /sed for dynamic memory allocation d+ring process r+ntime% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%%%%%%%%%%%%%%%%%%% 'age no" 0 Process State:- ach process may be in one of the following states d+ring e*ec+tion:-
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
(i) 2ew:- The process is being created(ii) 3+nning:- instr+ctions are being e*ec+ted%(iii) 4aiting:- The process in waiting for some event to occ+rs s+ch as an ,5O
completion or reception of a signal%(iv) 3eady:- The process is waiting to be assigned to a processor%(v) Terminated:-
The process has finished e*ec+tion
6 Only one process can be r+nning on any processor at any instant%
Process control Block:-
ach process is represented by a process control block ('CB) 7 also called a task
(i) /ser ode(ii) $ernel ode or +pervisor ode or system ode or 'rivileged ode%
Mode Bit :-,t is +sed to disting+ish between +ser mode and kernel mode%
(a) Aor +ser mode: - ode 7 bit 1(b) Aor kernel mode :- ode 7 bit
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 9
Timer:-
DTimer is +sed to ens+re that the operating system maintains control over the C'/
D timer can be set to interr+pt the comp+ter after a specified period%
D4e can +se the timer to prevent a +ser program from r+nning too long%
ork ! " :-4hen a process forks" it creates a copy of itself
,n the child process" the ret+rn val+e of the fork is !ero%
,n the parent process" the ret+rn val+e is the ', of the newly created child process%
The fork operation creates a separate address space for the child%
Both the parent and child processes posses the same code segments" b+t e*ec+te
independently of each other%
Aor (int iE iFnE , GG)
Aork ( )
Aor this program ( n -1) child will be created%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% ;
+ltithreading
Problems #it$ traditional processes :-
(i) Traditional processes have separate address spaces%(ii) 'rocess creation is e*pensive%(iii) 'rocess switch is e*pensive%(iv) haring memory areas among processes is non- trivial
(v) process is a single thread of e*ec+tion%
T$reads:-
tread is a basic +nit of C'/ +tili!ation% ,t comprises :-
,t shares with other threads belonging to the name process its code section" data section"
and other operating system reso+rces" s+ch as open filer and signals%
6 any operating system kernels are now m+ltithreaded%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% <
Benefits of +ltithreading:-
(i) 3esponsiveness : -+ltithreading an interactive application may allow a program to contin+e r+nning
even it part of it is blocked or is performing a length operation" thereby increasing
responsiveness to the +ser%(ii) 3eso+rces haring :-
Threads share the address space and reso+rces of the process to which they
belong%(iii) conomy :-(a) Thread creation is m+ch simpler than process creation%(b) Thread switch is simple%(c) Comm+nication bl+e threads are simple%(d)
(iv) /tili!ation of m+ltiprocessor architect+res:-Threads can r+n parallel on different processors%
Types of Threads:-T#o types:-
(1) /ser-level threads :- (managed by thread library)$ernel not aware of threads%
D/nder non preemptive sched+ling" once the C'/ has been allocated to a process" theprocess keeps the C'/ +ntil it releases the C'/ either by terminating or by switching to the
waiting state%
D 2on preemptive sched+ling is also called as cooperative sched+ling%
D4henever a process switches from the r+nning state to the ready state or waiting state to the
ready state" and if sched+ling takes place in these case then the sched+ling is called
preemptive sched+ling%
D sched+ling is preemptive if once a process has been given the C'/ can taken away%
'riority sched+ling can be either preemptive or non preemptive%
preemptive priority sched+ling algorithm will preempt the C'/ if the priority of
the newly arrived process is higher than the priority of the c+rrently r+nning
process%
maIor problem with priority sched+ling algorithms is indefinite bloching or
starvation%
sol+tion to the problem of indefinite blockage of low-priority processes is aging%
/ging :-
ging is a techni@+e of grad+ally increasing the priority of process that wait in the
system for a long time%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 18
!0" 1ound- 1obin Sc$eduling :-The ro+nd-robin sched+ling algorithm is designed especially for time-sharing
systems%,t is similar to ACA sched+ling" b+t preemption is added to switch between
processes%The ready @+e+e is treated as a circ+lar @+e+e% The C'/ sched+ler goes aro+nd
the ready @+e+e" allocating the C'/ to each process for a time interval of +p to 1
time @+ant+m%!2" Multile+el 'ueue Sc$eduling : -
m+ltilevel @+e+e sched+ling algorithm partitions the ready @+e+e into several
separate @+e+es%The processes are permanently assigned to one @+e+e" generally based on the
properties of the process" s+ch as memory si!e" process priority" or process type%ach @+e+e has its own sched+ling algorithm for e*ample" separate @+e+e might
be +sed for foregro+nd and backgro+nd processes" and these processes might
have separate sched+ling re@+irement%,n addition" there m+st be sched+ling among the @+e+es" which is commonly
implemented as fi*ed-priority preemptive sched+ling%
There are three ways to deal with the deadlock problem:-
(i) 4e can +se a protocol to prevent or avoid deadlocks" ens+ring that the system will
never enter a deadlock state%(ii) 4e can allow the system to enter a deadlock state" detect it" and recover%(iii) 4e can ignore the problem altogether and pretend that deadlock never occ+r in the
system%(iv) 4e can ignore the problem altogether and pretend that deadlocks never occ+r in the
system%
Deadlock Pre+ention:-
By ens+ring that at least one of these conditions cannot hold" we can prevent the
occ+rrence of a deadlock:-
(i) +t+al *cl+sion(ii) .old and wait(iii) 2o preemption(iv) Circ+lar wait
The drawback of this method is low device +tili!ation and red+ced system
thro+ghp+t%
Deadlock /+oidance :-
deadlock - avoidance algorithm dynamically e*amines the reso+rce- allocation
state to ens+re that a circ+lar wait condition can never e*ist%The reso+rce 7 allocation state is defined by the n+mber of available and
allocated reso+rces and the ma*im+m demand of the processes%There are two algorithms for deadlock-avoidance:-
4hen a +sers re@+ests a set of reso+rces" the system m+st determine whether the
allocation of these reso+rces will leave the system in a safe state% ,f it will" the reso+rces are
allocatedE otherwise" the process m+st wait +ntil some other process release eno+gh reso+rces%
Let n be the n+mber of processes in the system and m be the n+mber of reso+rces
types% 4e need the following data str+ct+res :-
(i) vailable :- vector of length m indicates the n+mber of available reso+rces of each type%,f vailable (I) e@+als k" there are k-instances of reso+rces type 3I available%
(ii) a* :- n n * m matri* defines the ma*im+m demand of each process%,A a* (i) (I) k" then process 'i may re@+est at most k- instance of reso+rce
type 3I%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no%
(iii) llocation :- n n * m matri* defines the n+mber of reso+rces of each type c+rrently allocated
to each process%,f llocation (i) (I) k" then process 'i is c+rrently allocated k instances of
reso+rce type $I%(iv) 2eed :-
n n * m matri* indicated the remaining reso+rces need of each process%,f 2eed (i) (I) $ then process 'i may need $ more instance of reso+rces type 3I
to complete its task%
2eed (i) (I) a* (i) (I) 7 llocation (i) (I)
*ample :- Consider a system with five processes po thro+gh p1 and three reso+rces types "B
and C 3eso+rces type has 1 instances" B has 9 instances" and C has < instances" +ppose
that at time To" the following snapshot of the system has been taken:-
llocation a* vailable
B C BC B C
' 1 % <90 0 0
'1 0
' 0 H
'0 1 1
'8 800
2ow check :- (i) 4hether the system is in safe state or notQ
(iii) 4hether re@+est (1"") by p1 can be immediately grantedQ(iv) 4hether re@+est ( 0"0") by p8 can be immediately granted Q
'rocess m+st e*plicitly name the receiver or sender of a message (symmetric
addressing)
- end ('" message)%end message to process '%3eceive (K" message)%3eceive message from K%
,n a client- server system" the server does not have to know the name of a specific client
in order to receive a message% ,n this case" a variant of the receive operation can be+sed (asymmetric addressing%)
-receive (," message)% 3eceive a pending message from any process% 4hen a
message arrives" , is let to the name of the sender%
,n direct comm+nication" the interconnection between the sender and receiver
has the following characteristics :-
(i) link is established a+tomatically" b+t the processes need to know each others
identify%(ii) +ni@+e link is associated with the two processes%(iii) The link is +s+ally bi-directional" b+t it can be +nidirectional%
9ndirect (ommunication :-4ith indirect comm+nication" the messages are sent to and received from
mailbo*es" or points%
mailbo* can be viewed abstractly as an obIect into which messages can be
placed by processes and from which messages can be removed%
The send ( ) and receive ( ) primitives are defined as follows:-
-send (" message )% end a message to mailbo* %
-receive ( message)% 3eceive a message from mailbo* %
#enerally" a mailbo* is associated with many senders and receivers%
,n some systems" only one receiver is associated with a partic+lar mailbo*" s+ch a
mailbo* is often called a port%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no%9
,n indirect comm+nication" the interconnection between the sender and receiver
has the following characteristics:-
(i) link is established between two processes only if they share a mailbo*%(ii) link may be associated with more than two processes%(iii) Comm+nicating processes may have different links between them" each
corresponding to one mailbo*%
Producer – consumer Problem : -
prod+cer process prod+ces information that is cons+med by a cons+mer process%
One sol+tion to the prod+cer- cons+mer problem +ses shared memory% To allow
prod+cer and cons+mer processes to r+n conc+rrently" we m+st have available a b+ffer
of items that can be filled by the prod+cer" and emptied by the cons+mer%
The prod+cer and cons+mer m+st be synchroni!ed" so that the cons+mer does
not try to cons+me an item that has not yet been prod+ced%
'eterson?s sol+tion is restricted to two processes that alternate e*ec+tion between their
critical sections and remainder sections% The processes are n+mbered 'i and ' ;* where I 1- i
'eterson?s sol+tion re@+ires two data items to be shared between the two processes :-
,nt t+rn E
Boolean Alag VW"
The variable t+rn indicates whose t+rn it is to enter its critical section%The flag array is +sed to indicate that a process is ready to enter its critical section%
T$e structure o4 process Pi in Petersons Solution:-
o M
(entry section)
Critical section
(e*it section)
3emainder section
N
To enter the critical section" process pi first sets flag ViW to be tr+e and then sets t+rn tothe val+e I" thereby asserting that if the other process wishes to enter the critical section" it can
do so%
,f both processes try to enter at the same time" t+rn will be set to both i and I at
ro+ghly the same time% Only one of these assignments will lastE the other will occ+r b+t will be
overwritten immediately% The event+al val+e of t+rn decides which of the two processes is
6 'eterson?s sol+tion is a software based sol+tion%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 0
ynchroni!ation .ardware:-,n general" we can state that any sol+tion to critical section problem re@+ires a simple
total 7 a lock 3ace conditions are prevented by re@+iring that critical regions be protected by
locks%
o M
Critical section
3emainder section
N 4hile (time) E
The critical section problem co+ld be solved simply in a +niprocessor environment if we
wo+ld prevent interr+pts from occ+rring while a shared variable was being notified% ,n this
manner" we wo+ld be s+re that the c+rrent se@+ence of instr+ction wo+ld be allowed to e*ec+te
in order witho+t preemption % This is the approach taken by non preemptive kernel%
/nfort+nately" this sol+tion is not as feasible in a m+ltiprocessor environment% isabling
interr+pts on a m+ltiprocessor can be time cons+ming%
any modern comp+ter systems therefore provide special hardware instr+ctions thatallow +s either to test and modify the content of a word or to swap the contents of two words
atomically%
(i) Test nd et ( ) instr+ction :-The important characteristic of this instr+ction is that this instr+ction is e*ec+ted
atomically% Th+s" if two Test nd etc) instr+ctions are e*ec+ted sim+ltaneo+sly
(each on a different ('/)" they will be e*ec+ted se@+entially in some arbitrary
order%Boolean Test and et (Boolean Lock)M
Boolean rv - lockE% Lock 7 tr+eE3etr+n rvE
N
,f the machine s+pports the Test and et ( ) instr+ction then we can implement
m+t+al e*cl+sion by declaring a Boolean variable lock" initiali!ed to false%
4hen some other process e*ec+tes a signal ( ) operation" the process is restarted by a wake +p( ) operation" which changes the process from the waiting state to the ready state% The process
is then placed in the ready @+e+e%
ignal ( semaphore 9)
M
D val+e -GE
,f ( s D val+es F)
M
3emove a process p from s D list"
4ake +p (')E
N
N
6ote : - ltho+gh +nder the classical definition of semaphores with b+sy waiting the semaphore
val+e is never negative" this implementation may have negative semaphore val+es"% ,f the
semaphore val+e is negative" its magnit+de is the n+mber of process waiting on that
semaphore%
The critical aspect of semaphores is that they be e*ec+ted atomically% 4e m+st
g+arantee that no two process can e*ec+te wait ( ) and signal () operations on the same
semaphore at the same time%
This is a critical-section problem" and in a single processor environment" we can solve it
by simply inhibiting interr+pts d+ring the time the wait () and signal () operations are e*ec+ting%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%
'age no% 08
,n a m+ltiprocessor environment disabling interr+pt on every processor can be a diffic+lt
task% Therefore ' system m+st provide alternative locking techni@+es 7 s+ch as spinlocks 7
to ens+re that wait () and signal () are performed atomically%
6ote :-
,t is important to admit that we have not completely eliminated b+sy waiting with this
definition of the wait () and signal () operations% .ere we have limited the b+sy waiting to the
critical sections of the wait (c) and signal ( ) operations" and these sections are short%
Deadlocks and Star+ation:-
The implementation of a semaphore with a waiting @+e+e may res+lt in a sit+ation where
two or more processes are waiting indefinitely for an event that can be ca+sed only by one of
the waiting processes% The event in @+estion is the e*ec+tion of a signal ( ) operation%
4hen s+ch a state is reached" these processes are said to be deadlocked%
,t manages the metadata information% ,t manages the directory str+ct+re to provide the
file-organi!ation mod+le with the information the latter needs" given a symbolic file name%
,t maintains file str+ct+re via file 7 control blocks%
Aile control Block ( ACB):-
,t contains information abo+t the file" incl+ding ownership" permissions" and location of
the file contents%
ile system used by +arious kind o4 OS :-
(i) /,2[ D/2,[ Aile system (/A)" which is based on Berkeley Aast file system (AA)%(ii) 4indows D AT" AT0" 2TA(iii) Lin+* D*tended Aile system ( e*t > e*t 0)
everal on 7disk and in-memory str+ct+re are +sed to implement a file system% These str+ct+re
vary depending on the operating system and the file system b+t general principles apply%
On disk" the file system may contain following information:-
(i) Boot Control Block ( per ol+me) :-,t contains information needed by the system to boot a O form that vol+mes%
,n /A" it is called the boot block%
,n 2TA" it is called the partition boot sector%
(ii) ol+me ( control Block (per vol+me) :-,t contains vol+me details s+ch as the member of blocks in the partition" si!e of
the blocks etc%,n /A" it is called a s+per block%,n 2TA" it is stored in master file table%
(iii) irectory tr+ct+re (per file ystem):-
,t is +sed to organi!e the files%,n /A" this incl+des file names and associated inode n+mbers%,n 2TA" it is stored in the master file table%
(iv) Aile control Block 7ACB (per file) :-,t contain details abo+t the file incl+ding file permissions" ownership" si!e etc,n /A" this is called the inode block%,n 2TA" this information is act+ally stored within the master file table%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%%
'age no% 0<
The in- memory information is +sed for both file system management and performance
improvement via coaching% The data are loaded at mo+nt time and discarded at dismo+nt%
The str+ct+res may incl+de the ones described below :-
(i) ,n-memory mo+nt table :-,t contains information abo+t each mo+nted vol+mes%
(ii) ,n-memory directory-str+ct+re cache : -,t holds the directory information of recently accessed directories?%
(iii) ystem-wide open- file table:-,t contains the ACB of each open file%
.ere we +se a first level inde* block to point to a set of second level inde*
blocks" which in t+rn points to the file blocks
( C) Combined cheme :-
This scheme is +sed in /ni* file system (/%A%)%
,n this scheme" we keep the first 19 pointers of the inde* block in file?s inode% The
first 1 of these pointers point to direct blocksE that is they contain addresses of blocks thatcontain data of the file% Th+s" the data for small files do not need a separate inde* block%
The ne*t three pointers point to indirect blocks% The first points to a single indirect
block% The second points to a do+ble indirect block% The last pointer contains the address of a
triple indirect block%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 0H
tr+ct+re of /2,[ Aile ystem :-
Boot
Block
+per
Block
,node
Block
ata
Block
6 ,f the si!e of blocks is 1$B and each address re@+ires ∆ B" then total memory addressed
by each entry of inode table is :-
1$B G9;$B G9;*9;$B G9;*9;*9;$B%
ree Space Management:-
(1) Bit ap or Bit ector : -The free-space list is implemented as a bit map or bit vector% ach block is
represented by 1- bit% ,f the block is free" the bit is 1" if the block is allocated" the
The average time re@+ired to reach a storage location in memory and obtain its contents
is called the access time%
disk drive is attached to a comp+ter by a set of wires called an ,5O B+s%The data transfer on a b+s are carried o+t by special electronic processors called controllers :-
(i) .ost Controller :-This is the controller at the comp+ter end of the b+s%
(ii) isk Controller :-,t is b+ilt into each disk drive%
/ddressing in Magnetic Disks:-
odern disk drives are addressed as large one-dimensional array of logical blocks%
The one-dimensional array of logical blocks is mapped onto the sectors of the disk
fre@+ently%
ector O is the first sector of the first track on the o+termost cylinder% The mapping
proceeds in order thro+gh that track" then thro+gh the rest of the tracks in that cylinder and thentro+gh the rest of the cylinders from o+termost to innermost%
(onstant 5inear =elocity ! (5=" :-
On edia that +se constant linear velocity (CL)" the density of bits per track is +niform%
The drive increases its rotation speed as the head moves from the o+ter to the inner tracks to
keep the same rate of data moving +nder the head%
This method is +sed in C-3O and -3O drives%
(onstant /ngular =elocity !(/=" :-
The disk rotation speed remains constant" and the density of bits decreases form inner
tracks to o+ter tracks to keep the data rate constant%
The algorithm is intrinsically fair" b+t it generally does not provide the fastest
service%(ii) hortest eek Time Airst (TA) ched+ling :-
The ,A algorithm selects the re@+est with minim+m seak time from the c+rrent
head position%,t may ca+se starvation of some re@+ests%This algorithm is not optimal%
(iii) C2 ched+ling :-
The disk arm starts at one end of the disk and moves towards the other end"
servicing re@+ests as it reaches each cylinder%
t the other end" the direction of head movement is reversed%
,t is sometimes called the elevator algorithm%
(iv) Circ+lar C2 (C-C2) ched+ling:-,t is similar to C2 sched+ling" however when the head reaches the other end"
it immediately ret+rn to the beginning of the disk" witho+t servicing any re@+est
on the ret+rn trip%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 80
Disk ormatting:-
new magnetic disk is a blank slate :,t is I+st a platter of a magnetic recording material
(i) 'hysical Aormatting :-
Before a disk can store data" it m+st be divided into sectors that the disk
controller can read and write" This process is called low-level formatting or
physical formatting%
,T fills the disk with a special data str+ct+re for each sector%
(ii) Logical Aormatting :-
.ere the operating system stores the initial file-system data str+ct+res onto thedisk%These data str+ct+res may incl+de maps of free and allocated space and an
initial empty directory%
1o# Disk :- ome operating systems give special programs the ability to +se a disk partition as
a large se@+ential array of logical blocks" witho+t any file-system data str+ct+re% This array is
sometimes called the raw disk" and ,5O to this array is termed as raw ,5O%
Disk Block :-
disk block is the +nit of data transfer b5w disk and memory%
Block si!e m+st be m+ltiple of sector si!e"Block si!e cannot e*ceed the si!e of track%
,f records can span more than one block in a disk" this organi!ation is called spanned%
4henever a record is larger than a block" we m+st +se a spanned organi!ation%
&nspanned 1ecords:-
,f records are not allowed to cross block bo+ndaries" the organi!ation is called
+nspanned %This is +sed with fi*ed- length records having BP3%
Blocking actor :-+ppose that the block si!e in B bytes% Aor a file of fi*ed length records of si!e 3 bytes"
with B P 3" we can fit bfr LB53\ records per block%
The val+e bfr is called the blocking factor%
The ma*im+m n+mber of records that can fit in a disk block" is called the blocking factor
(bfr)%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 89
Types o4 Organi<ation o4 iles :-
There are three types of organi!ation of files :-
(1) Ailes of /nordered 3ecords (.eap Ailes) :-The records are placed in the file in order in which they are inserted" so new
records are inserted at the end of the file%This organi!ation is often +sed with additional access paths" s+ch as the
secondary inde*es%() Ailes of Ordered 3ecords (orted Ailes):-
4e can physically order the records of a file on disk based on the val+es of one
of the their fields-called the ordering field%,t the ordering field is also a key field of the file" then the field is called the
ordering key field%(0) .ash Ailes :-
The idea behind hashing is to provide a f+nction h called a hash f+nction" that isapplied to the hash field val+e of a record and yields the address of the disk
block in which the record is stored"%Aor most records" we need only a single-block access to retrieve that recorded%The search condition m+st be an e@+ality condition one single field%
6 ll the above organi!ation of files are called primary organi!ation%
9ndexes :-
The inde* str+ct+res typically provide secondary access paths to access the records
witho+t affecting the physical placement of records on disk%
Dense /nd sparse 9ndexes:- dense inde* has an inde* entry for every search key val+e%
sparse inde* has inde* entries for only some of the search val+es%
primary inde* is specified on the ordering key field of an ordered file of records% ,f the
ordering field is not a key field" then cl+stering inde* is +sed% file can have at most one physical ordering field" so it can have at most one primary
inde* or one cl+stering inde*" b+t not both%
secondary inde* can be specified on any non-ordering field of a file%
Primary 9ndexes:-
primary inde* is an ordered file whose records are of fi*ed length with two fields" The
first field is of the same data type as the ordering key field 7 called the primary key 7 of the data
file" and the second field is a pointer to a disk block%
There is one inde* entry in the inde* file for each block in the data file" that has the val+e
of the primary key field for the first record in the block and a painter to that block%
Total no% of entries in the inde* is same as the no% of disk blocks in the ordered data file%
primary inde* is a non-dense ( sparse) inde*%
maIor problem with a primary inde* 7as with any ordered file 7 is insertion and deletion of
records%
(lustering 9ndexes :-
,f records of a file are physically ordered on a non-key field" that field is called the
cl+stering field%
cl+stering inde* is also an ordered file with two field with two field the first is same as
cl+stering field" and the second field is a block pointer%
There is one entry in the cl+stering inde* for each distinct val+e of the cl+stering field"
containing the val+e and the pointer to the first block in the data file that has a record with thatval+e%
cl+stering inde* is also a non dense (sparse) inde*" beca+se it has an entry for every
distinct val+e of the inde*ing field" rather than for every record in the file%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 8<
Secondary 9ndexes:-
,t is also an ordered file with two fields% The first field is of the same data type as some
non-ordering field of the data file that is an inde*ing field% The second field is either a block
painter or record painter%
There can be many secondary inde*es for the same file%
,t the secondary inde* is on a key field" then there is one inde* entry for each recorded in the
data file% .ence s+ch an inde* is dense%
,f the secondary inde* is on a non-key field" then n+mero+s records in the data file can have the
same val+e for the inde*ing field% There are vario+s options for implementing s+ch an inde*%
secondary inde* provides a logical ordering on the records by the inde*ing field%
m+ltilevel inde* considers the inde* file (first level) as an offered file with a distinct
val+e for each $ (i) % .ence we create a primary inde* for the first level%
This inde* to the first level is called the second level of the m+ltilevel inde*" and so on%
4e re@+ire a second level only if the first level needs more than one block of disk
storage and so on%
ach level red+ces the n+mber of entries at the previo+s level by a factor of fo-the inde*fan 7o+t
,f the first level has r " entries and the blocking factor 7 which is also the fan-o+t for the
inde* is bfr fo " then the first level needs V(r 1%5f )W blocks"
4hich is there fore the n+mber of entries r " needed of the second level of the inde*%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'age no% 8=
B-Trees :-
The B-Tree is a search tree with additional constraints that ens+re that the tree is always
balanced%
B -tree of order p" when +sed as an access str+ct+re on a key field to search for
records in a data file" can be defined as follows:-
(1) ach internal node in the B-tree is of the form:-
Fp1"Fk1"'r1"P'"F$"'3P"--------Fk@"'r@ P" '1P
4here @F p% ach 'i is a tree pointes- a pointer to another node in the B-tree
ach 'r is a data pointer 7 a pointer to the record whose search key field val+e is e@+al to ki
() 4ithin each node" $1 F k F ---- F $@-1
(0) Aor all search key field val+es [ in the s+b tree pointed at by 'i" 4e have :-$ i-1 F * F ki for 1F i F @"[ F $i for i -1" and
$ i-1 F * for i @%
(8) ech node has at most ' tree painters%(9) ach node" e*cept the root and leaf nodes" has at least V(p5)W tree pointers% The
root node has at least two tree pointers% The root node has at least two tree
pointer +nless it is only node in the tree%(;) node with @ tree pointer" @p"has @-1 search key field val+es%(<) ll leaf nodes are at the same level" leaf nodes have the same str+ct+re as
internal nodes e*cept that all of this tree pointers 'i are n+ll%