Вы находитесь на странице: 1из 15

FILE MANAGEMENT IN UNIX

1. How are devices represented in UNIX?


All devices are represented by files called special files that are located
in/dev directory. Ths! device files and other files are na"ed and accessed in the sa"e
#ay. A $re%lar file$ is &st an ordinary data file in the dis'. A $bloc' special file$
represents a device #ith characteristics si"ilar to a dis' (data transfer in ter"s of bloc's).
A $character special file$ represents a device #ith characteristics si"ilar to a 'eyboard
(data transfer is by strea" of bits in se*ential order).
2. What is 'inode'?
All UNIX files have its description stored in a strctre called $inode$. The inode
contains info abot the file+si,e! its location! ti"e of last access! ti"e of last "odification!
per"ission and so on. -irectories are also represented as files and have an associated
inode. In addition to descriptions abot the file! the inode contains pointers to the data
bloc's of the file. If the file is lar%e! inode has indirect pointer to a bloc' of pointers to
additional data bloc's (this frther a%%re%ates for lar%er files). A bloc' is typically .'.
Inode consists of the follo#in% fields/
File o#ner identifier
File type
File access per"issions
File access ti"es
N"ber of lin's
File si,e
Location of the file data
3. Brief abot the director! representation in UNIX
A Uni0 directory is a file containin% a correspondence bet#een filena"es and
inodes. A directory is a special file that the 'ernel "aintains. 1nly 'ernel "odifies
directories! bt processes can read directories. The contents of a directory are a list of
filena"e and inode n"ber pairs. 2hen ne# directories are created! 'ernel "a'es t#o
entries na"ed $.$ (refers to the directory itself) and $..$ (refers to parent directory).
3yste" call for creatin% directory is "'dir (pathna"e! "ode).
". What are the Uni# s!ste$ calls for I%&?
open(pathna"e!fla%!"ode) + open file
creat(pathna"e!"ode) + create file
close(filedes) + close an open file
read(filedes!bffer!bytes) + read data fro" an open file
#rite(filedes!bffer!bytes) + #rite data to an open file
lsee'(filedes!offset!fro") + position an open file
dp(filedes) + dplicate an e0istin% file descriptor
dp4(oldfd!ne#fd) + dplicate to a desired file descriptor
fcntl(filedes!c"d!ar%) + chan%e properties of an open file
ioctl(filedes!re*est!ar%) + chan%e the behavior of an open file
The difference bet#een fcntl anf ioctl is that the for"er is intended for any open file!
#hile the latter is for device+specific operations.
'. How do !o chan(e )ile *ccess +er$issions?
Every file has follo#in% attribtes/
o#ner$s ser I- ( 56 bit inte%er )
o#ner$s %rop I- ( 56 bit inte%er )
File access "ode #ord
$r # 0 +r # 0+ r # 0$
(ser per"ission+%rop per"ission+others per"ission)
r+read! #+#rite! 0+e0ecte
To chan%e the access "ode! #e se ch"od(filena"e!"ode).
E0a"ple 5/
To chan%e "ode of "yfile to $r#+r#+r++$ (ie. read! #rite per"ission for ser +
read!#rite per"ission for %rop + only read per"ission for others) #e %ive the ar%s as/
ch"od("yfile!7668) .
Each operation is represented by discrete vales
$r$ is 8
$#$ is 4
$0$ is 5
Therefore! for $r#$ the vale is 6(894).
E0a"ple 4/
To chan%e "ode of "yfile to $r#0r++r++$ #e %ive the ar%s as/
ch"od("yfile!7:88).
,. What are lin-s and s!$bolic lin-s in UNIX file s!ste$?
A lin' is a second na"e (not a file) for a file. Lin's can be sed to assi%n "ore
than one na"e to a file! bt cannot be sed to assi%n a directory "ore than one na"e or
lin' filena"es on different co"pters.
3y"bolic lin' $is$ a file that only contains the na"e of another file.1peration on
the sy"bolic lin' is directed to the file pointed by the it.;oth the li"itations of lin's are
eli"inated in sy"bolic lin's.
<o""ands for lin'in% files are/
Lin' ln filena"e5 filena"e4
3y"bolic lin' ln +s filena"e5 filena"e4
.. What is a )I)&?
FIF1 are other#ise called as $na"ed pipes$. FIF1 (first+in+first+ot) is a special
file #hich is said to be data transient. 1nce data is read fro" na"ed pipe! it cannot be
read a%ain. Also! data can be read only in the order #ritten. It is sed in interprocess
co""nication #here a process #rites to one end of the pipe (prodcer) and the other
reads fro" the other end (cons"er).
/. How do !o create special files li-e na$ed pipes and device files?
The syste" call "'nod creates special files in the follo#in% se*ence.
5. 'ernel assi%ns ne# inode!
4. sets the file type to indicate that the file is a pipe! directory or special file!
=. If it is a device file! it "a'es the other entries li'e "a&or! "inor device n"bers.
For e0a"ple/
If the device is a dis'! "a&or device n"ber refers to the dis' controller and "inor
device n"ber is the dis'.

0. 1iscss the $ont and n$ont s!ste$ calls
The privile%ed "ont syste" call is sed to attach a file syste" to a directory of
another file syste"> the n"ont syste" call detaches a file syste". 2hen yo "ont
another file syste" on to yor directory! yo are essentially splicin% one directory tree
onto a branch in another directory tree. The first ar%"ent to "ont call is the "ont
point! that is ! a directory in the crrent file na"in% syste". The second ar%"ent is the
file syste" to "ont to that point. 2hen yo insert a cdro" to yor ni0 syste"$s drive!
the file syste" in the cdro" ato"atically "onts to /dev/cdro" in yor syste".
12. How does the inode $ap to data bloc- of a file?
Inode has 5= bloc' addresses. The first 57 are direct bloc' addresses of the first
57 data bloc's in the file. The 55th address points to a one+level inde0 bloc'. The 54th
address points to a t#o+level (doble in+direction) inde0 bloc'. The 5=th address points to
a three+level(triple in+direction)inde0 bloc'. This provides a very lar%e "a0i"" file si,e
#ith efficient access to lar%e files! bt also s"all files are accessed directly in one dis'
read.
11. What is a shell?
A shell is an interactive ser interface to an operatin% syste" services that allo#s an ser
to enter co""ands as character strin%s or thro%h a %raphical ser interface. The shell
converts the" to syste" calls to the 13 or for's off a process to e0ecte the co""and.
3yste" call reslts and other infor"ation fro" the 13 are presented to the ser thro%h
an interactive interface. <o""only sed shells are sh!csh!'s etc.
3E<TI1N + II
?@1<E33 M1-EL and I?<
1. Brief abot the initial process se3ence while the s!ste$ boots p.
2hile bootin%! special process called the $s#apper$ or $schedler$ is created #ith
?rocess+I- 7. The s#apper "ana%es "e"ory allocation for processes and inflences
<?U allocation. The s#apper intrn creates = children/
the process dispatcher!
vhand and
dbflsh
#ith I-s 5!4 and = respectively.
This is done by e0ectin% the file /etc/init. ?rocess dispatcher %ives birth to the
shell. Uni0 'eeps trac' of all the processes in an internal data strctre called the ?rocess
Table (listin% co""and is ps +el).
2. What are varios I1s associated with a process?
Uni0 identifies each process #ith a ni*e inte%er called ?rocessI-. The process
that e0ectes the re*est for creation of a process is called the $parent process$ #hose ?I-
is $?arent ?rocess I-$. Every process is associated #ith a particlar ser called the $o#ner$
#ho has privile%es over the process. The identification for the ser is $UserI-$. 1#ner is
the ser #ho e0ectes the process. ?rocess also has $Effective User I-$ #hich deter"ines
the access privile%es for accessin% resorces li'e files.
%etpid() +process id
%etppid() +parent process id
%etid() +ser id
%eteid() +effective ser id
3. 4#plain for-56 s!ste$ call.
The Afor'()$ sed to create a ne# process fro" an e0istin% process. The ne#
process is called the child process! and the e0istin% process is called the parent. 2e can
tell #hich is #hich by chec'in% the retrn vale fro" Afor'()$. The parent %ets the child$s
pid retrned to hi"! bt the child %ets 7 retrned to hi".
". +redict the otpt of the followin( pro(ra$ code
"ain()
B
for'()>
printf(CDello 2orldEC)>
F
Answer:
Dello 2orldEDello 2orldE
Explanation/
The for' creates a child that is a dplicate of the parent process. The child be%ins
fro" the for'().All the state"ents after the call to for'() #ill be e0ected t#ice.(once by
the parent process and other by child). The state"ent before for'() is e0ected only by
the parent process.
'. +redict the otpt of the followin( pro(ra$ code
"ain()
B
for'()> for'()> for'()>
printf(CDello 2orldEC)>
F
Answer:
CDello 2orldC #ill be printed . ti"es.
Explanation/
4Gn ti"es #here n is the n"ber of calls to for'()
,. 7ist the s!ste$ calls sed for process $ana(e$ent8
System calls Description
for'() To create a ne# process
e0ec() To e0ecte a ne# pro%ra" in a process
#ait() To #ait ntil a created process co"pletes its e0ection
e0it() To e0it fro" a process e0ection
%etpid() To %et a process identifier of the crrent process
%etppid() To %et parent process identifier
nice() To bias the e0istin% priority of a process
br'() To increase/decrease the data se%"ent si,e of a process
.. How can !o (et%set an environ$ent variable fro$ a pro(ra$?
Gettin% the vale of an environ"ent variable is done by sin% A%etenv()$.
3ettin% the vale of an environ"ent variable is done by sin% Aptenv()$.
/. How can a parent and child process co$$nicate?
A parent and child can co""nicate thro%h any of the nor"al inter+process
co""nication sche"es (pipes! soc'ets! "essa%e *ees! shared "e"ory)! bt also have
so"e special #ays to co""nicate that ta'e advanta%e of their relationship as a parent
and child. 1ne of the "ost obvios is that the parent can %et the e0it stats of the child.
0. What is a 9o$bie?
2hen a pro%ra" for's and the child finishes before the parent! the 'ernel still
'eeps so"e of its infor"ation abot the child in case the parent "i%ht need it + for
e0a"ple! the parent "ay need to chec' the child$s e0it stats. To be able to %et this
infor"ation! the parent calls A#ait()$> In the interval bet#een the child ter"inatin% and the
parent callin% A#ait()$! the child is said to be a A,o"bie$ (If yo do Aps$! the child #ill have
a AH$ in its stats field to indicate this.)
12. What are the process states in Uni#?
As a process e0ectes it chan%es state accordin% to its circ"stances. Uni0
processes have the follo#in% states/
@nnin% / The process is either rnnin% or it is ready to rn .
2aitin% / The process is #aitin% for an event or for a resorce.
3topped / The process has been stopped! sally by receivin% a si%nal.
Ho"bie / The process is dead bt have not been re"oved fro" the process table.
11. What Happens when !o e#ecte a pro(ra$?
2hen yo e0ecte a pro%ra" on yor UNIX syste"! the syste" creates a special
environ"ent for that pro%ra". This environ"ent contains everythin% needed for the
syste" to rn the pro%ra" as if no other pro%ra" #ere rnnin% on the syste". Each
process has process conte0t! #hich is everythin% that is ni*e abot the state of the
pro%ra" yo are crrently rnnin%. Every ti"e yo e0ecte a pro%ra" the UNIX syste"
does a for'! #hich perfor"s a series of operations to create a process conte0t and then
e0ecte yor pro%ra" in that conte0t. The steps inclde the follo#in%/
Allocate a slot in the process table! a list of crrently rnnin% pro%ra"s 'ept by
UNIX.
Assi%n a ni*e process identifier (?I-) to the process.
i<opy the conte0t of the parent! the process that re*ested the spa#nin% of the ne#
process.
@etrn the ne# ?I- to the parent process. This enables the parent process to e0a"ine
or control the process directly.
After the for' is co"plete! UNIX rns yor pro%ra".
12. What Happens when !o e#ecte a co$$and?
2hen yo enter $ls$ co""and to loo' at the contents of yor crrent #or'in%
directory! UNIX does a series of thin%s to create an environ"ent for ls and the rn it/ The
shell has UNIX perfor" a for'. This creates a ne# process that the shell #ill se to rn
the ls pro%ra". The shell has UNIX perfor" an e0ec of the ls pro%ra". This replaces the
shell pro%ra" and data #ith the pro%ra" and data for ls and then starts rnnin% that ne#
pro%ra". The ls pro%ra" is loaded into the ne# process conte0t! replacin% the te0t and
data of the shell. The ls pro%ra" perfor"s its tas'! listin% the contents of the crrent
directory.
13. What is a 1ae$on?
A dae"on is a process that detaches itself fro" the ter"inal and rns!
disconnected! in the bac'%rond! #aitin% for re*ests and respondin% to the". It can also
be defined as the bac'%rond process that does not belon% to a ter"inal session. Many
syste" fnctions are co""only perfor"ed by dae"ons! incldin% the send"ail dae"on!
#hich handles "ail! and the NNT? dae"on! #hich handles U3ENET ne#s. Many other
dae"ons "ay e0ist. 3o"e of the "ost co""on dae"ons are/
init/ Ta'es over the basic rnnin% of the syste" #hen the 'ernel has finished the boot
process.
inetd/ @esponsible for startin% net#or' services that do not have their o#n stand+
alone dae"ons. For e0a"ple! inetd sally ta'es care of inco"in% rlo%in! telnet! and
ftp connections.
cron/ @esponsible for rnnin% repetitive tas's on a re%lar schedle.
1". What is 'ps' co$$and for?
The ps co""and prints the process stats for so"e or all of the rnnin%
processes. The infor"ation %iven are the process identification n"ber (?I-)!the a"ont
of ti"e that the process has ta'en to e0ecte so far etc.
1'. How wold !o -ill a process?
The 'ill co""and ta'es the ?I- as one ar%"ent> this identifies #hich process to
ter"inate. The ?I- of a process can be %ot sin% $ps$ co""and.
1,. What is an advanta(e of e#ectin( a process in bac-(rond?
The "ost co""on reason to pt a process in the bac'%rond is to allo# yo to do
so"ethin% else interactively #ithot #aitin% for the process to co"plete. At the end of
the co""and yo add the special bac'%rond sy"bol! I. This sy"bol tells yor shell to
e0ecte the %iven co""and in the bac'%rond.
E0a"ple/ cp J.J ../bac'pI (cp is for copy)
1.. How do !o e#ecte one pro(ra$ fro$ within another?
The syste" calls sed for lo#+level process creation are e0eclp() and e0ecvp().
The e0eclp call overlays the e0istin% pro%ra" #ith the ne# one ! rns that and e0its. The
ori%inal pro%ra" %ets bac' control only #hen an error occrs.
e0eclp(path!fileKna"e!ar%"ents..)> //last ar%"ent "st be NULL
A variant of e0eclp called e0ecvp is sed #hen the n"ber of ar%"ents is not 'no#n in
advance.
e0ecvp(path!ar%"entKarray)> //ar%"ent array shold be ter"inated by NULL
1/. What is I+:? What are the varios sche$es available?
The ter" I?< (Inter+?rocess <o""nication) describes varios #ays by #hich
different process rnnin% on so"e operatin% syste" co""nicate bet#een each other.
Larios sche"es available are as follo#s/
+ipes8
1ne+#ay co""nication sche"e thro%h #hich different process can
co""nicate. The proble" is that the t#o processes shold have a co""on
ancestor (parent+child relationship). Do#ever this proble" #as fi0ed #ith the
introdction of na"ed+pipes (FIF1).
;essa(e <ees 8
Messa%e *ees can be sed bet#een related and nrelated processes
rnnin% on a "achine.
=hared ;e$or!8
This is the fastest of all I?< sche"es. The "e"ory to be shared is "apped
into the address space of the processes (that are sharin%). The speed achieved is
attribted to the fact that there is no 'ernel involve"ent. ;t this sche"e needs
synchroni,ation.
Larios for"s of synchronisation are "te0es! condition+variables! read+#rite
loc's! record+loc's! and se"aphores.
3E<TI1N + III
MEM1@M MANAGEMENT
1. What is the difference between =wappin( and +a(in(?
=wappin(8
2hole process is "oved fro" the s#ap device to the "ain "e"ory for
e0ection. ?rocess si,e "st be less than or e*al to the available "ain "e"ory. It is
easier to i"ple"entation and overhead to the syste". 3#appin% syste"s does not handle
the "e"ory "ore fle0ibly as co"pared to the pa%in% syste"s.
+a(in(8
1nly the re*ired "e"ory pa%es are "oved to "ain "e"ory fro" the
s#ap device for e0ection. ?rocess si,e does not "atter. Gives the concept of the virtal
"e"ory.
It provides %reater fle0ibility in "appin% the virtal address space into the
physical "e"ory of the "achine. Allo#s "ore n"ber of processes to fit in the "ain
"e"ory si"ltaneosly. Allo#s the %reater process si,e than the available physical
"e"ory. -e"and pa%in% syste"s handle the "e"ory "ore fle0ibly.
2. What is $a>or difference between the Historic Uni# and the new B=1 release of Uni#
=!ste$ ? in ter$s of ;e$or! ;ana(e$ent?
Distoric Uni0 ses 3#appin% N entire process is transferred to the "ain "e"ory
fro" the s#ap device! #hereas the Uni0 3yste" L ses -e"and ?a%in% N only the part
of the process is "oved to the "ain "e"ory. Distoric Uni0 ses one 3#ap -evice and
Uni0 3yste" L allo# "ltiple 3#ap -evices.
3. What is the $ain (oal of the ;e$or! ;ana(e$ent?
It decides #hich process shold reside in the "ain "e"ory!
Mana%es the parts of the virtal address space of a process #hich is non+core
resident!
Monitors the available "ain "e"ory and periodically #rite the processes into the
s#ap device to provide "ore processes fit in the "ain "e"ory si"ltaneosly.
". What is a ;ap?
A Map is an Array! #hich contains the addresses of the free space in the s#ap
device that are allocatable resorces! and the n"ber of the resorce nits available there.
This allo#s First+Fit allocation of conti%os bloc's of a resorce. Initially the
Map contains one entry N address (bloc' offset fro" the startin% of the s#ap area) and the
total n"ber of resorces.
Oernel treats each nit of Map as a %rop of dis' bloc's. 1n the allocation and
freein% of the resorces Oernel pdates the Map for accrate infor"ation.
'. What sche$e does the @ernel in Uni# =!ste$ ? follow while choosin( a swap device
a$on( the $ltiple swap devices?
Oernel follo#s @ond @obin sche"e choosin% a s#ap device a"on% the "ltiple
s#ap devices in Uni0 3yste" L.
,. What is a Ae(ion?
A @e%ion is a continos area of a processPs address space (sch as te0t! data and
stac'). The 'ernel in a Q@e%ion TableP that is local to the process "aintains re%ion.
@e%ions are sharable a"on% the process.
.. What are the events done b! the @ernel after a process is bein( swapped ot fro$ the
$ain $e$or!?
2hen Oernel s#aps the process ot of the pri"ary "e"ory! it perfor"s the
follo#in%/
5 57!777
Address Units
Oernel decre"ents the @eference <ont of each re%ion of the process. If the
reference cont beco"es ,ero! s#aps the re%ion ot of the "ain "e"ory!
Oernel allocates the space for the s#appin% process in the s#ap device!
Oernel loc's the other s#appin% process #hile the crrent s#appin% operation
is %oin% on!
The Oernel saves the s#ap address of the re%ion in the re%ion table.
/. Is the +rocess before and after the swap are the sa$e? Bive reason.
?rocess before s#appin% is residin% in the pri"ary "e"ory in its ori%inal for".
The re%ions (te0t! data and stac') "ay not be occpied flly by the process! there "ay be
fe# e"pty slots in any of the re%ions and #hile s#appin% Oernel do not bother abot the
e"pty slots #hile s#appin% the process ot.
After s#appin% the process resides in the s#ap (secondary "e"ory) device. The
re%ions s#apped ot #ill be present bt only the occpied re%ion slots bt not the e"pty
slots that #ere present before assi%nin%.
2hile s#appin% the process once a%ain into the "ain "e"ory! the Oernel
referrin% to the ?rocess Me"ory Map! it assi%ns the "ain "e"ory accordin%ly ta'in%
care of the e"pty slots in the re%ions.
0. What do !o $ean b! Carea 5ser area6 or Cbloc-?
This contains the private data that is "aniplated only by the Oernel. This is local
to the ?rocess! i.e. each process is allocated a +area.
12. What are the entities that are swapped ot of the $ain $e$or! while swappin( the
process ot of the $ain $e$or!?
All "e"ory space occpied by the process! processPs +area! and Oernel stac' are
s#apped ot! theoretically.
?ractically! if the processPs +area contains the Address Translation Tables for the
process then Oernel i"ple"entations do not s#ap the +area.
11. What is )or- swap?
for'() is a syste" call to create a child process. 2hen the parent process calls
for'() syste" call! the child process is created and if there is short of "e"ory then the
child process is sent to the read+to+rn state in the s#ap device! and retrn to the ser
state #ithot s#appin% the parent process. 2hen the "e"ory #ill be available the child
process #ill be s#apped into the "ain "e"ory.
12. What is 4#pansion swap?
At the ti"e #hen any process re*ires "ore "e"ory than it is crrently allocated!
the Oernel perfor"s E0pansion s#ap. To do this Oernel reserves eno%h space in the
s#ap device. Then the address translation "appin% is ad&sted for the ne# virtal address
space bt the physical "e"ory is not allocated. At last Oernel s#aps the process into the
assi%ned space in the s#ap device. Later #hen the Oernel s#aps the process into the
"ain "e"ory this assi%ns "e"ory accordin% to the ne# address translation "appin%.
13. How the =wapper wor-s?
The s#apper is the only process that s#aps the processes. The 3#apper operates
only in the Oernel "ode and it does not ses 3yste" calls instead it ses internal Oernel
fnctions for s#appin%. It is the archetype of all 'ernel process.
1". What are the processes that are not bothered b! the swapper? Bive Aeason.
Ho"bie process/ They do not ta'e any p physical "e"ory.
?rocesses loc'ed in "e"ories that are pdatin% the re%ion of the process.
Oernel s#aps only the sleepin% processes rather than the Qready+to+rnP
processes! as they have the hi%her probability of bein% schedled than the
3leepin% processes.
1'. What are the re3ire$ents for a swapper to wor-?
The s#apper #or's on the hi%hest schedlin% priority. Firstly it #ill loo' for any
sleepin% process! if not fond then it #ill loo' for the ready+to+rn process for s#appin%.
;t the "a&or re*ire"ent for the s#apper to #or' the ready+to+rn process "st be
core+resident for at least 4 seconds before s#appin% ot. And for s#appin% in the process
"st have been resided in the s#ap device for at least 4 seconds. If the re*ire"ent is not
satisfied then the s#apper #ill %o into the #ait state on that event and it is a#a'en once
in a second by the Oernel.
1,. What are the criteria for choosin( a process for swappin( into $e$or! fro$ the
swap device?
The resident ti"e of the processes in the s#ap device! the priority of the processes
and the a"ont of ti"e the processes had been s#apped ot.
1.. What are the criteria for choosin( a process for swappin( ot of the $e$or! to the
swap device?
The processPs "e"ory resident ti"e!
?riority of the process and
The nice vale.
1/. What do !o $ean b! nice vale?
Nice vale is the vale that controls Bincre"ents or decre"entsF the priority of
the process. This vale that is retrned by the nice () syste" call. The e*ation for sin%
nice vale is/
+riorit! D 5Erecent :+U sa(eF%constant6 G 5baseC priorit!6 G 5nice vale6
1nly the ad"inistrator can spply the nice vale. The nice () syste" call #or's
for the rnnin% process only. Nice vale of one process cannot affect the nice vale of the
other process.
10. What are conditions on which deadloc- can occr while swappin( the processes?
All processes in the "ain "e"ory are asleep.
All Qready+to+rnP processes are s#apped ot.
There is no space in the s#ap device for the ne# inco"in% process that are
s#apped ot of the "ain "e"ory.
There is no space in the "ain "e"ory for the ne# inco"in% process.
22. What are conditions for a $achine to spport 1e$and +a(in(?
Me"ory architectre "st based on ?a%es!
The "achine "st spport the QrestartableP instrctions.
21. What is Hthe principle of localit!I?
ItPs the natre of the processes that they refer only to the s"all sbset of the total
data space of the process. i.e. the process fre*ently calls the sa"e sbrotines or
e0ectes the loop instrctions.
22. What is the wor-in( set of a process?
The set of pa%es that are referred by the process in the last QnP! references! #here
QnP is called the window of the #or'in% set of the process.
23. What is the window of the wor-in( set of a process?
The #indo# of the #or'in% set of a process is the total n"ber in #hich the
process had referred the set of pa%es in the #or'in% set of the process.
2". What is called a pa(e falt?
?a%e falt is referred to the sitation #hen the process addresses a pa%e in the
#or'in% set of the process bt the process fails to locate the pa%e in the #or'in% set. And
on a pa%e falt the 'ernel pdates the #or'in% set by readin% the pa%e fro" the secondary
device.
2'. What are data strctres that are sed for 1e$and +a(in(?
Oernel contains 8 data strctres for -e"and pa%in%. They are!
?a%e table entries!
-is' bloc' descriptors!
?a%e fra"e data table (pfdata)!
3#ap+se table.

2,. What are the bits that spport the de$and pa(in(?
Lalid! @eference! Modify! <opy on #rite! A%e. These bits are the part of the pa%e
table entry! #hich incldes physical address of the pa%e and protection bits.
?a%e address
A%e <opy on #rite Modify @eference Lalid ?rotection
2.. How the @ernel handles the for-56 s!ste$ call in traditional Uni# and in the =!ste$ ?
Uni#J while swappin(?
Oernel in traditional Uni0! "a'es the dplicate copy of the parentPs address space
and attaches it to the childPs process! #hile s#appin%. Oernel in 3yste" L Uni0!
"aniplates the re%ion tables! pa%e table! and pfdata table entries! by incre"entin% the
reference cont of the re%ion table of shared re%ions.
2/. 1ifference between the for-56 and vfor-56 s!ste$ call?
-rin% the for'() syste" call the Oernel "a'es a copy of the parent processPs
address space and attaches it to the child process.
;t the vfor'() syste" call do not "a'es any copy of the parentPs address space!
so it is faster than the for'() syste" call. The child process as a reslt of the vfor'()
syste" call e0ectes e0ec() syste" call. The child process fro" vfor'() syste" call
e0ectes in the parentPs address space (this can over#rite the parentPs data and stac' )
#hich sspends the parent process ntil the child process e0its.
20. What is B==5Bloc- =tarted b! =!$bol6?
A data representation at the "achine level! that has initial vales #hen a pro%ra"
starts and tells abot ho# "ch space the 'ernel allocates for the n+initiali,ed data.
Oernel initiali,es it to ,ero at rn+ti"e.
32. What is +a(eC=tealer process?
This is the Oernel process that "a'es roo"s for the inco"in% pa%es! by s#appin%
the "e"ory pa%es that are not the part of the #or'in% set of a process. ?a%e+3tealer is
created by the Oernel at the syste" initiali,ation and invo'es it thro%hot the lifeti"e of
the syste". Oernel loc's a re%ion #hen a process falts on a pa%e in the re%ion! so that
pa%e stealer cannot steal the pa%e! #hich is bein% falted in.
31. Na$e two pa(in( states for a pa(e in $e$or!?
The t#o pa%in% states are/
The pa%e is a%in% and is not yet eli%ible for s#appin%!
The pa%e is eli%ible for s#appin% bt not yet eli%ible for reassi%n"ent to other virtal
address space.
32. What are the phases of swappin( a pa(e fro$ the $e$or!?
?a%e stealer finds the pa%e eli%ible for s#appin% and places the pa%e n"ber
in the list of pa%es to be s#apped.
Oernel copies the pa%e to a s#ap device #hen necessary and clears the valid
bit in the pa%e table entry! decre"ents the pfdata reference cont! and places
the pfdata table entry at the end of the free list if its reference cont is 7.
33. What is pa(e falt? Its t!pes?
?a%e falt refers to the sitation of not havin% a pa%e in the "ain "e"ory #hen
any process references it.
There are t#o types of pa%e falt /
Lalidity falt!
?rotection falt.
3". In what wa! the )alt Handlers and the Interrpt handlers are different?
Falt handlers are also an interrpt handler #ith an e0ception that the interrpt
handlers cannot sleep. Falt handlers sleep in the conte0t of the process that cased the
"e"ory falt. The falt refers to the rnnin% process and no arbitrary processes are pt to
sleep.
3'. What is validit! falt?
If a process referrin% a pa%e in the "ain "e"ory #hose valid bit is not set! it
reslts in validity falt.
The valid bit is not set for those pa%es/
that are otside the virtal address space of a process!
that are the part of the virtal address space of the process bt no physical address is
assi%ned to it.
3,. What does the swappin( s!ste$ do if it identifies the ille(al pa(e for swappin(?
If the dis' bloc' descriptor does not contain any record of the falted pa%e! then
this cases the atte"pted "e"ory reference is invalid and the 'ernel sends a
E=e($entation violationF si%nal to the offendin% process. This happens #hen the
s#appin% syste" identifies any invalid "e"ory reference.
3.. What are states that the pa(e can be inJ after casin( a pa(e falt?
1n a s#ap device and not in "e"ory!
1n the free pa%e list in the "ain "e"ory!
In an e0ectable file!
Mar'ed Rde"and ,eroS!
Mar'ed Rde"and fillS.
3/. In what wa! the validit! falt handler concldes?
It sets the valid bit of the pa%e by clearin% the "odify bit.
It recalclates the process priority.
30. *t what $ode the falt handler e#ectes?
At the Oernel Mode.
"2. What do !o $ean b! the protection falt?
?rotection falt refers to the process accessin% the pa%es! #hich do not have the
access per"ission. A process also incr the protection falt #hen it atte"pts to #rite a
pa%e #hose cop! on write bit #as set drin% the for'() syste" call.
"1. How the @ernel handles the cop! on write bit of a pa(eJ when the bit is set?
In sitations li'e! #here the copy on #rite bit of a pa%e is set and that pa%e is
shared by "ore than one process! the Oernel allocates ne# pa%e and copies the content to
the ne# pa%e and the other processes retain their references to the old pa%e. After
copyin% the Oernel pdates the pa%e table entry #ith the ne# pa%e n"ber. Then Oernel
decre"ents the reference cont of the old pfdata table entry.
In cases li'e! #here the copy on #rite bit is set and no processes are sharin% the
pa%e! the Oernel allo#s the physical pa%e to be resed by the processes. ;y doin% so! it
clears the copy on #rite bit and disassociates the pa%e fro" its dis' copy (if one e0ists)!
becase other process "ay share the dis' copy. Then it re"oves the pfdata table entry
fro" the pa%e+*ee as the ne# copy of the virtal pa%e is not on the s#ap device. It
decre"ents the s#ap+se cont for the pa%e and if cont drops to 7! frees the s#ap space.
"2. )or which -ind of falt the pa(e is chec-ed first?
The pa%e is first chec'ed for the validity falt! as soon as it is fond that the pa%e
is invalid (valid bit is clear)! the validity falt handler retrns i""ediately! and the
process incr the validity pa%e falt. Oernel handles the validity falt and the process #ill
incr the protection falt if any one is present.
"3. In what wa! the protection falt handler concldes?
After finishin% the e0ection of the falt handler! it sets the $odif! and protection
bits and clears the cop! on write bit. It recalclates the process+priority and chec's for
si%nals.
"". How the @ernel handles both the pa(e stealer and the falt handler?
The pa%e stealer and the falt handler thrash becase of the shorta%e of the
"e"ory. If the s" of the #or'in% sets of all processes is %reater that the physical
"e"ory then the falt handler #ill sally sleep becase it cannot allocate pa%es for a
process. This reslts in the redction of the syste" thro%hpt becase Oernel spends too
"ch ti"e in overhead! rearran%in% the "e"ory in the frantic pace.

Вам также может понравиться