0% found this document useful (0 votes)
417 views69 pages

OS - Operating System Akash

The document discusses several topics related to operating systems: 1. It explains why page size is always a power of 2 for efficient address calculation and memory allocation. 2. It defines multiprogramming operating systems as systems that can load multiple programs into memory at once but run only one at a time, allowing other ready processes to execute when the current process performs I/O to maximize CPU usage. 3. It provides a brief overview of what a process control block contains, including process state, identification, and scheduling information.

Uploaded by

Elon musk
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)
417 views69 pages

OS - Operating System Akash

The document discusses several topics related to operating systems: 1. It explains why page size is always a power of 2 for efficient address calculation and memory allocation. 2. It defines multiprogramming operating systems as systems that can load multiple programs into memory at once but run only one at a time, allowing other ready processes to execute when the current process performs I/O to maximize CPU usage. 3. It provides a brief overview of what a process control block contains, including process state, identification, and scheduling information.

Uploaded by

Elon musk
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/ 69

=

~
./}
Time : 1.30 Hrs.

Note: Ait empt Q no. 1 whicich h is¢ compulsory


and any two more questions.
Q.1(a@) Why page size is always re
presented as power of 2?
isAnsiad: It i a ati efficient to break the address into X page bits and Y
offset bits,
periorm arithmetic on the address to calculate the page
Because each bit position re number and offset.
presents a power of 2, splitting an address bet
results in a page size that is a power of 2. han, oe
Q.1(6) What is multiprogramming operatin
g system? Explain.
Ans: Ina multiprogramming system there are one or
more programs loaded in
en nee which are ready to execute. Only one program at a time is able
to get the
or executing its instructions (i.e., there is at most one proces
s running on the
system) while all the others are waiting their turn.
The main idea of multiprogramming is to maximize the use of CPU time. Indeed,
suppose the currently running process is performing an I/O task (which, by definiti
on,
does not need the CPU to be accomplished). Then, the OS may interrupt that process
and give the control to one of the other in-main-memory programs that are ready to
execute (i.e. process context switching). In this way, no CPU time is wasted by the system
waiting for the I/O task to be completed, and a running process keeps executing until
either it voluntarily releases the CPU or when it blocks for an I/O operation. Therefore,
the ultimate goal of multiprogramming is to keep the CPU busy as long as there are
processes ready toexecute. | |
Note that in order for such a system to function properly, the OS must be able to
load multiple programs into separate areas of the main memory and provide the required
protection to avoid the chance of one process being modified by another one. Other
problems that need to be addressed when having multiple programs in memory
is fragmentation as programs enter or leave the main memory. Another issue that needs
to be handled as well is tnat large programs may not fit at once in memory which can be
solved by using paging and virtual memory. “i
Finally, note that if there are N ready processes and all of those are highly CPU-
bou nd (i.e. , they mos tly exe cut e CPU task s and non e or very few I/O oper atio ns), in the
case one pro gra m mig ht wait all the othe r N-1 ones to com ple te befo re
very worst
executing. |
Q.1.(c) Explain Process Control Block in brief?
A pro ces s in an ope rat ing sys tem is rep res ent ed by a dat a str uct ure kno wn as.
Ans:
a process control block (PCB) or process descriptor. The PCB contains important
information about the specific process including |
te of the pro ces s i.e., whe the r it is rea dy, run nin g, wai tin g, or
¢ The current sta
whatever. | . |
~e Unique identification of the process in order to track “which is which” information.
¢ A pointer to parent process.
¢ Similarly, a pointer to child process (if it exists),
:

System
. ~

th Semester, Operating
Sixth oe"
art of CPU scheduling information).
vee of proce SS ~
of processes.
ose e Ss (a p
é
yorr
emory
o locate m 2016-3
rea.
‘por Save a
nning OF.
essor it js ru
e The proc he What are the possible solutitions to bdlve this
tis star eer
Q.id) Wha
proble wm?Tn computer science, starvation ;
isi a problem encountered in concurrent
Ans:
here a process 18 perpetually denied necessary resources to process its work
algorithm. }
computin
~, W
-evatjogn may be caused by errors ina scheduling or mutual exclusion
we > be caused by resource leaks, and can be intentionally caused via a denial ut
-of-
k such as a fork bomb. 3 |
~aanStarattac
vation is similar to deadlock in that it causes a process
to freeze. Two or creating modular operating systems. Under the to
in an
processes become deadlocked when each of them is doing nothing while wait functionality and
and |
feat ures. are determined and th € separated into com
rce occu
resouation pied by anot her prog ram in the same
that is set.
cont On
inuo the
uslyothe r
give nhand.
to a
otk ro
Proc ea
ess e—
isin Information hiding is also important, because
it leaves programmers free tore
starv when it is waiting for a resource the low-level routines as they see fit, provided that the ext
Starvation-freedom is a stronger guarantee. than the absence of er processes, ernal interface of the routine
stays unchanged and that the routine itself performs the advertised task.
exclusion algorithm that must choose to let one of two processes into A system can be made modular in mafiy,ways. One met
picks one arbitrarily is deadlock-free, but not starvation-free. hod is the layered
approach, in which the operating system is broken up into a number
of layers (levels)
Possible solution: A possible solution to starvationj The bottom layer (layer 0) id the hardware; the highest (layer N) isthe user
interface.
with priority queue that also uses the aging technique. Aging isa te An operating-system layer is an implementation of an abstract object made up of
chnique ofgradually
increasing the priority of processes that wait in the sy stem for a long data and the operations that can manipulate those data. A typical operating — system
© time.
Q.1.(e) Explain race condition wit
) h Suitable e xample? layer-say, layer M-consists of data structures and a set of routines that can be invoked

Ans: Race conditions are most commonly by higher-level layers. Layer M, in turn, can invoke operations on lower-level layers.
In associated with computer Beton ¥
computer memory or storage, a race condition may occu The main advantage of the layered approach is simplicity of construction and
‘a large amount of data are receiv r if commands to read and write |

Paitin
ed at almost the Same instant, and the machine
debugging. The layers are selected so that each uses functions (operations) and services

wtingy
:
attempts to overwrite some or all of the old data while that ol of only lower-level layers. This approach simplifies debugging and system verification.
d data is still being read.

ait,
inn
The result may be one or more of the fo The first layer can be debugged without any concern for the rest of the system, because,
llowing:a computer crash, an “illegal oper

ES i
notification an ation,” by definition, it uses only the basic hardware (which is assumed correct) to implement

dim ta : i ee Si
d shutdown of the program, errors read

Ot
ing the old data or errors writing
the new data. A race condition can also occur if instructions
its functions. Once the first layer is debugged, its correct functioning can be assumed
are processed in the incorrect while the second layer is debugged, and so on. If an error is found during debugging of a
order. |

em
particular layer, the error must be on that layer, because the layers below it are already

ei
Example: Suppose for a moment that two processes need to perform a bit flip ata debugged. Thus, the design and implementation of the system is simplified.

sas
specific memory location. Under normal circumstances the operation should work like ' Each layer is implemented with only those operations provided by lower-level layers.

Soil Stn
this: ae | A layer does not need to know how these operations are implemented; it needs to know

,
Process 1 | Process 2 Memory Value | | ’ only what these operations do. Hence, each layer hides the existence of certain data
structures, operations, and hardware from higher-level layers. The major difficulty
Read value | 0 with the layered approach involves appropriately defining the various layers. Because
Flip value. 1 } layer can use only lower-level layers, careful planning is necessary. For
example, the
hes: Read value , 1 memory algorithms)
- device driver for the backing store (disk space used by virtual-
Flip value — 0 er level tha n the memory -manag ement rout ines, because memory
must be at a low

me mo ry va lu e fr om 0 to management requires the ability to use the backing store.


erforms a bi
e, Processbit1 p flip t fli p, ch an gi ng th e g-s tor e dri ver would —
this 2 ex
In ess amplperf orms a and changes the memory value from 1 to 0.If a race Other requir eme nt may not be so obv iou s. The bac kin
1. Proc then could potentially may nee d to wai t for V/O and the wi
the se two pro ces ses to ove rla p, the se qu en ce be above the CPU schedu ler , bec aus e the driver
condition occurred causing ore } ing thi s tim e. How eve r, on a lar ger sys tem, the CPU sched er
can be rescheduled dur
look more like this: abo ut all the act ive pro ces ses tha n can fit in a
Process 1 Process 2 Memory Value may have more information memory, req g
on may nee d to be swa ppe d in and out of
0 Therefore, this informati le r. iia
Read value iver routine to be be lo w the CPU sc he du
backing-store dr poli s eee —
Read value 0 emen ta ti on s is tha t th ey
A final problem with layered impl m ex ecuteser an 1/O ope
Flip value 1 For in st an ce ," wh en a us er pr og ra w oe
than ot he r types. yer, which calls th e me mo ry
Flip value “i is tr ap pe d to th e I/ O la
executes a system call that
m
Operating Syste
Sixth Semeste!, ; Ot a L.P. University(B.Tech+AB
9016 5 : 1 #1171 Ca 11s the CPU-scheduling layer, which
may be modified; is then
data may paggeq
neeg to be
Publisher 2016-5
processor program, storing your word processed document and storine a copy
At each ayer Aas overhead to the system call; the net resyjt is a of the
image that is being displayed on the monitor. And of course th e operating system itself
:
.
will also use up some memory.
does one ona non-layered system. These limitations
kes lon
:
1] back
a year
thentadv
lash against “53 layering stin ofrece ant laye
s ofr mod
s.ageFewe rs r;with more
ula
re causeG © ; igned, providing as ‘tic in : OMb 4Mb 8Mb 12Mb 16Mb
x zed ¢
rano ty menthebeing1
I tionali‘Jing lt probleme of layer definiti
|
on and interaction. 9 Operating we We Free Screan
\ Systern Software |Data Memory =
while avoiding : g System:
Main tasks © everal tasks which are performed by practically all operat Example Allocation of Computer Memory
tn - ye complexity of the computer the operating system is bein Ng systems,
§ used on.
Allocation of CPU Time
< regarare
These ta sks include:
munications between software and hardware. Most computers have only one microprocessor in their Central Processing Unit
Managing com
e (CPU). Therefore the CPU can only process one piece of data at a time. The CPU’s time
o n of c om p ute r memory.
e Alloc ati must be divided up between all of the tasks that the computer is currently carrying out.
time.
e Allocation of CPU If you were printing a document form a word processor application then the CPU’s time
s.
e Organising data on backing storage device would need to be divided up between:
n i c a t i o n s b e t w e e n S o f t w a r e a n d H a r d ware ¢ Letting you type on the computer.
Managing Commu
tically every program writte * Sending the document that is being printedto the printer. _
y task
There are manFor s whi ch prac n for a computer will
example:
need to carry out. * Updating the screen display to show you what is going on.
e Loading and saving data and programs.
- Chunks of the CPU’s time known as time slices are allocated to each task in turn.
e Communicating with peripherals such as a mouse or a printer
Time slices are normally very short so that each task cam appear to be running at the
e Displaying information on the VDU. same time.
There has to be some control over these activities to make sure that Organising Data on Backing Storage Devices
problems ms d do


not occur. Consider what might happen if a computer pro
program t
tryingto weet
wasvery Work and programs must be saved on a backing storage device so that they can be
)file

he
from i
a floppy disk and, at the same time, another program was

dd
kept when a computer is turned off. The operating system is responsible for organising

edemenanty ai
Therefore the operating system manages all of these tasks. If, for exam
ple, a program data on backing storage devices. Work and programs are saved as files which must be
- wants to save or print a file it must send a request to the o perating system
ibe ay asking it to organised so that they can be found and loaded when required. Each file is identified by

SiR
cals Odean
do so. The operating system will then carry out the task. Cy Case eae a filename.
Because an application such as a spreadsheet works by communicatin
g with the Most operating systems divide a backing storage device up into directories (also

Saal
operating system the application will probably only work with one particular known as folders). Files can be stored within each directory.

a
operating

ni atin
system. If you buy Microsoft Works for Windows 2000 it will only operate on computer active
s Q.2.(6) On a simple paged system, associative registers hold the most

di
bie the Windows 2000 operating system. If you want to use Microsoft Works with the references
page entries & full page table is stored in the main memory. If the

fren
-DOS operating system you will have to buy a different version of the application. sfied by the asso ciat ive regi ster s take 100n s & reference thr ough the main
sati
;
to be achieved on
memory page table take 180ns.What must be the hit ratio
Ss
| : /
Computer Softwar effective access time of 125ns?
Messages t 7 | Ans: Effective Access Time= [x*(m,+m,)] + [(1—x)*(c + m,+ m,)|
ters, M, represents
| Operating System Where m, represents references satisfied by associative regis
esents the hit
Electric Signals , reference through main memo ry, c repr esen ts acces s the page table , x repr

[ Computer Hardware ratio.


So, BAT = [x*(100+180)]+[(1-x)*(180+100+180)]
Putting commonly used operations such as saving data int othe operating
ati system 125 = (280x)+(460-460x) ,
also reduces the amount of work that a person writing a new application Sa ee =o
125 = 460-180x
Allocation of Computer Memory
.

180x = 460-125
180x = 335
x = 1,86%(Hit Ratio)

~~
=< 2
Q.2. ) Sixth
©xXambple me
hat j Belady: A i ~ Perating Sy
ps
S | stdm
Ans: elady’ omaly? Explain with the } l eat
i 0 frames Ile amaly is algo ~ P Of suitabig LP. University(B.Tech)-A
time© s? weesr éspage fs aul
atsa Toc B Publisher
Soese
m ' vi
lgI memochryom,alythe Usu all y, on increas; reasing the
ine as
Anom aly. Ty: ccur, Q.3.(6) Consider the fo
°°" When Pro ces s ex
- Chis ig true for at ‘ etmes, the reverse h
“Xecution is faster
time in milliseconds?
Example i frames “re allocated
ain page to © Dappens, i.e., the €xecut
finns dans © io Process
1: In th pro cess. This is Belady’,
€e faults are marked
P
S Case Assy With an “> oe: A 0
me fr am e 5;
oh B
i Requests
a7
1
. =
ewest P age A Og
C 2
Ol) “Or ye aS
| D 3
as rhe | E
Oldest Page ; 4
oar caleng Siac, Bi Draw the Gantt chart & find:
2: In thhis
eo ee 1
j case Assume (i) Average waiting time for these proces
frame Size is OS
4
B dau. Ga Baa Time Fir
ses with the shortest Remaining
| | st, Round Robin (Time quantum=3ms) & FC
FS scheduling algorithms.
“a (ii) Average turnaround time for these processes with the
Newest fiOe ene id
shortest Remaining
Page Time First, Round Robin (Time quantum=3ms)
& FCFS scheduling algorithms.
3f ALTE i 6 ORO ean 4f se : Ans: Gantt Chart for FCFS
i “
BPs po a dle al Oi
:
ig 2 ate ;:
S82 OO AI|BICIDIE
Oldest Page ae 3 9 0 10 15 23 27 38
83558 ne BD 1
In the first exampl Ore | - For FCFS:
e (with fewer pages),
there are 9 Page fau
In the second example lts
(with more pages) ther
e are 10 page faults
: ; Process | --AT BT cr | varacraD | wr-carey |
& criteria? A es: 10 10 10 0
Ans: There
scheduling algorithm -
are man y different criterja’s
to check when consi B 1 5 15 14 9
dering the “best” C 2 g 23 21 13
I. CPU utilization: |Ts D
make out| the best use
of CPU and not to, wast
3 4 27 24 20
cycle, CPU would be wo
real system, CPU usage sh
rking most of the
ti me (I de al ly 10 0%
e any CPU
of the time). Gcnsidering
E 4 uu 38 34 23
ould range from 40% (lightly a
loaded) to 90 (i) Average Waiting Time=(0+9+13+20+23)/5=65/5=13ms
|
(ii) Average Turnaround Time=(10+14+21+24+34)/5=103/5=20.6ms

~
.
Gantt Chart for SRTF

7
——
3. Turnaround time: It is the amount of time AIBIDICIA\E

em
i.e. The interval from time of submission of the pr
“pk
O° 2 6 10 18 27.38
~~
-
process(Wall clock time). Sas
ie
|
For SRTF:
Ate
“a
a

AT BT CT |. TAT=(CT-AT) =(TAT-BT) |
Process
Ainitiacn

Fog 0 10 27 27 . }
al

waiting for their turn to get into the CPU. B = 5 6 Be


,
=

6. Response time: Amount of time it takes fro m when Cc 2 8 18 a AG ‘


a request was submitted :
until the first response is produced. Remember, it is th
e time till the first response and D 3 4 10 1
not the completion of process execution (fj nal respon 4 11 38 34 b
se).
|
‘ -
E
10.2ms
(i) Average Waiting Time=(17+0+8+3+23)/5=51/5=
rag e Tu rn ar ou nd Ti me =( 27 +5 +1 6+ 7+ 34 )/ 5= 89/5=17.8ms
(ii) Ave
LP. University-(B.Tech}-AB Publisher
2016-9
thes ee 1. Pk has already chosen its number when Pi doés the
| S259 12 15 18 20 last test before entering its
For RR(Time quantum
93 2 c1 e critical section.
3ms) co In this case, if (number({il, i) < (numberfk].k) d
eee S
Process equal, so (numbert(i],i) > (number{k],k). Pscaaia dhs soeata ‘dai tvéanice she
AT BT CT TAT=(CT-AT) cirtical section before Pk does, and Pi will looping at the last while daloc
aecs SEG
A 0 10 31
condition does not hold, which is modified by Pk when it exits from its eikicuha ie ;
3 i a Note that if Pk get a new number again, it must be larger than that of Pi’s. aa
e 1 5 20 19 a 2. Pk did not chose its number when Pi does the last test before entering its critical
2 8 33 section.
31 c
D 3 4 24 In this case, since Pk has chosen its number when Pi is in its critical section, Pk
21 s must chose its number later than Pi. According to the algorithm, Pk can only get a bigger
E 4 Li 38 34 ; oie number than Pi, so (number{i],i) < number((k],k) holds.
(i) Average Waiting Time=(2 14+14+ Q.4.(b) Define a monitor?
e a . . ~

23+417+23)/5=98/5=19.6ms a

| Ans: In concurrent programming, a monitor is a synchronization construct


that
. eae Purnaround Time=(314+1943142 1+34)/5=136/5= mutu al excl usion and the ability to wait (block) for a certain
27.2ms allows thre ads to have both
Q.4. (a) Explain bakery algorithm. Prov me true. Moni tors also have a mechanis in for signa lling other threads
condition to beco
e th at it satisfies all the three met. A monitor consists of a mutex (lock) object
requirements for critical section proble that their condition has been
m. | able s. A cond itio n vari able is basi call y a container of threads
and condition vari a mechanism for threads to
Ans: Bakery algorithm: The Bakery algorithm is one of the simp cond itio n. Moni tors prov ide
lest kp that are waiting for a certain
SO utions to the mutual exclusion problem for the general case of N process. e acce ss in orde r to wait for some condition to be met, before
The ce temporarily give up exclusiv
ming their task.
idea is that each non-thinking process has a variable that indicates
the position e that regaining exclusive access and resu t, or modu le that uses
a thre ad-s afe class , objec
| process in a hypothetical queue of all the non-thinking processes. Each process in dies Another definition of monitor is s to a meth od or variable by
orde r to safel y allo w acces
“queue scans the variables of the other processes, and enters the critical section only wrapped mutual exclusion in of a moni tor is that its methods are
char acte rist ic
upon determining that it is at the head of the queue. } more than one thread. The defining in time, at most one thread may be
At each poin t
executed with mutual exclusion: it can also aaa ae
But the resulting algorithm is still not easy to understand. So in this note we first Using a-ce ndit ion vari able (s),
executing any of its methods. (thus usin g the abov e = om ofa
look at a simplified version of the bakery algorithm, based a coarser grain of atomicity a certain cond itio n
! ae ability for threads to wait on of moni tor” will be refer red to as a
than is allowed by the mutual exclusion problem. “mon itor ”). For the rest of this article, this sens e
eee
Solution to the Critical Section Problem must meet three conditions... ”.

<
“thread-safe object/c lass /mod ule’ we

*
Fro em?

:
lain the Dining Phi los oph ers
1. Mutual exclusion: If process is executing in its critical section, no other process

ies
(ec). ion problem

.
are a clas sic sync hron izat
ers problems

le
ak e Phi los oph

6 eee:
is executing in its critical section Sc Proc esse e): xy
Sequ enti al
there exists some (E. W. Dijkstra. Co-operating

:
s is ex ec ut in g in its cri tic al sec tio n and room ae .

eit
2. Progress: If no pr oc es e is a dini ng
onl y tho se pro ces ses tha t are Dining Philosophers: Ther = : gee ,

sin Str ge
al sec tio ns, the n k .
processes that wish to enter their critic with five chairs. ie } e
th e de ci si on of wh ic h will circ ular tabl e
section ca n pa rt ic ip at e in chopstick. 1n
not executing in their remainder e is a sing le Bs

§7
tween each plat ann
indefinitely san d


is de ci si on cann ot be po st pone d Near the room are five
and th hett i.
enter its critical section next, oe is abowl of spag y :
thinking, but who —
ci de qu ic kly who enters most of thei r time
sect io n, ca n de who spend m aa
If no process is in critical ar e pu t on the @- so they can thin k name
th e cr it ic al se ction so in pr ac tice , others hungry and need to eat sit at the table, P
en te r must
Only one process can In order to eat, a philosop
her
of a pl at e, t h e n serve and
left and ri gh t
a e ee ~< | i the tw o c h op st ic ks to th e
ro
ex is t a b o u n d on th e scar
e d w a i t i n g : T h e r e must f achetti on the plate. th e fo ll ow in g pseudocode
3. Boun d al s e c t i o n s af te r a process ilosopher is represented by
w e d to e n ter thei r cr it ic = oa a k ph
senoabae s ar e a l l o q u e s t is
i g r a nted
ti c a l s e c t i o n a nd before t h a t r e
e n t e r it s critical — process P{i]
to ent e r it s cr i
a k e s a reque s t to
r o m when a p r o c e s s m while true do
is the t i m e f
The wait "HINK;
est is granted another turn 4 )
t get KL i+ 1 mo d 5)
section until that requ i s a s
itical sma e c t i o n , it d oe s n o
| rACK UP (C HO PS TI CK L) , CH OP ST IC
rocess e n t e r s it
In practice, once a p anag CHOP S T I C K L i + 1 m o d 5])
p r o ce s s ge ts a t ur n ( m N (C HO PS TI CK L
until a waiting ‘ttiical s e c t i: o n p r o b l em ae TDOW
i r e m e n t s f o r c r i its q b
T h e t h r e e r e q u ha s al read y ch os en }
i t i c a ] se ct io n an d Pk(k!=i)
t h a t P i is in its cr
Suppose
t h e r e a r e t w o cases:
- number'[k],
a =e Oa

Th at the s ns, and, of courge two phi dey, ;


€ problem is to g ame time © Philogoy’ 7 =
; esi Dhe ECO
who tries to BAT, eventually does to satisfy the liveness conditi iu oo” oe EXAMINATION [APRI
Discussion. Of cour 2 aR Philosop SIXTH SEMESTER [B.TECH ~
your own by exploring varicueon tine is 0 go off and try to sol OPERATING SYSTEM [\ETCS
ETCé. .
ve this prob] m,. -ime:1.30 Hrs 304]
= -1 mutua
are likely to quickly
l exclusio a y unter
n prétlen : bit Philosophers might use i acquir
ae:the s ame deadlock and livelock scen © chopst; Note: Attempt Q no. 1 Which
Is too you will quick] aQT10s wh is com
Primitive a synchronization heshh q > y See in this case that mut © Saw in Q.1.(a) Explai pulsory and any two more questions
‘ msm for solvin exc] ain seek time andr
ng this problem
in nmost operatin & Systeins lon ce scheduling?
imilar ofsolutio
re n Pr tions ns are found
the original treatme Ans : Seek Ti
mechanism he
eei
SDE Oy, na them me: Seek time is the time taken tol
sais was introducing in his original article. A\em Mee the Semapp, | track where the data is to be read or write. So the dink acca mr re
n value, S, with two associated atomic operatio Pisemaphore} ig an inte _Mminimum average seek time is better né algorithm that gives
DOWN(S) wait until S > 0,| then dec| rement ns: Ber Fin
S di see —_ Rotational Latency is the time taken by the desired sector of
. . a position so that i :
UP(S) increment S _ Scheduling algorithm that oe Mivtads bonihiciadd ueaaoriatale eee
In time-sharin g systems, “waitin 4 r.
: _. Q.1.(6) What are the four conditions that
may put processes on a wait-list fen tate - Pm by the operating system Which _ be possible? ch One ae
accomplished by busy-waiti execution. In hardware, “waiting” », Ans: Deadlock sds
™m | ° ock Conditions
sialiaa - ate signal
in g or by some form of explicit ay be { 1, Mutual Exclusion: The resources involved must be un-shareable
; otherwise
_ the processes would not be prevented from using the resource when necessary.
2. Hold and wait or partial allocation: The processes must hold the resources
_ they have already been allocated while waiting for other (requested) resources. If the
process had to release its resources when a new resource or resources were requested,
_ deadlock could not occur because the process would not prevent others from using
_ resources that it controlled. i
3. No preemption: The processes must not have resources taken away while that
___ resource is being used. Otherwise, deadlock could not occur since the operating system
could simply take enough resources from running processes to enable any process to
finish.
4, Resource waiting or circular wait: A circular chain of processes, with each
process holding resources which are currently being requested by the next process in the
chain, cannot exist. If it does, the cycle theorem (which states that “a cycle in the
resource graph is necessary for deadlock to occur”) indicated that deadlock could occur.
Q.1.(c) What are various file attributes?
grant or
Ans: File attributes are settings associated with computer files that
ain righ ts to how a user or the oper atin g syst em can acce ss that file. For
_ deny cert
IBM comp atib le comp uter s runn ing MS- DOS or Microsoft Windows have
example,
capa bili ties of havi ng read , arch ive, syst em, and hidden attributes.
Jae
ws a file to be read , but noth ing can be writ ten to the file or
a *Read-only - Allo
changed. ~ | |
the file.
a ¢Archive - Tells Windows Backup to backup
|
‘ System - System file.
will not be show n whe n doin g a regular dir from DOS.
h Hidden - File
Exp lai n the ter m cac hin g and buffering?
Q.1.@)
Ans: Buffering: m o r y (t he buffer).
se rv ed ar ea of m e
e Preloading data into a re
Sixth Semester, Operating System
: :
A philosopher may THINK ind fi
finis
aah cea eeindef
ee P and PUTEver
inately.
DOW y philosopher
N thelr hemelica: lle enty
Stically, but these are atomic actio IN €ithe al}
cannot use a single CHOPSTICK at the same nat, and, of course, two phil aes SE C
eae Th 1e problem is; to design a protocol to satisfy the liveness condi "Phe, Pr OND TERM EXAMINATION [AP
o tries to EAT, eventually does. "on: any phiy, SIXTH SEMESTER [B ene
yourDisc
bwn ussi axpl Of
by on. 3
viiig varies auch ania to go off and try to Solve this
“Dh -TECH |
| : OPERATING SYSTEM [ETCS ~ 3 304]
are al
You mutu to quic
y usion kly
likelexcl encounter the ha ieee might use to acquire cho em Op ‘Time : 1.30 Hrs,
the orbblent hit €
deadlock and livelock Scenarj *P8tick, Note: Attempt Q reas M.M. : 30
1s too primitive a Synchr
hronization you will
mech quick
anis m lyf, see vjin this case that Mutua]
ve We
exc] SawsQ no. I seek
Q.1.(a) Explain whichti is compulsory and
; any two more questi ons. c
Siiiarsclutions wee a or solving this problem c USiop, | ime and rotational latency in disk sched uling?
ound 1n most operat
renditions of the original t perating systems textbooks. Aj] 6 Ans:§S| ‘ coos.
inechaniaea he was ucdhatne kita, 5 by Dijkstra, which motivated the (2.5x4=10
ta ae track hase the eee
oa a is the time taken to locate the disk arm to a Es
or boolean value, S, with two eisbulinciacs article A\emph{semaphore} ig ant ‘ rm minimum average seek ies athena So the disk scheduling algorithm that gives
, omic operations Ber ;
DOWN(S)
wait until S > 0, then decre
. X
?
& Rotational
disk to
Latenc . Rotati
oe
lL te . .
ona Jatency 1s the time taken by the desired sector
UP(S) ment S; rotate into a position so that it can access the read/write heads. So the ‘igh of
increment S$ (ia Scheduling algorithm that gives minimum rotational latency is better.
In time-sharing s aPC | er ReR 3 a. oe be are the four conditions that must be present for a deadlock to
: ystems,
“waiting” is implementedby the. ing si
» May put processes on a wait- : tion. In : hardware
list for later execu Pee, > “waiti system
ng Mich =—
_ accomplished by busy- waiting or by some form of explicit
eit > Wwaltin Js Ans: D o,8

passing. signaling, cuch an % ctv ach a area


; a YKen 9 1. Mutual Exclusion: The resources involved must be un-shareable; otherwise
ane ei-vs| the processes would not be prevented from using the resource when nece
ssary.
oH 2. Hold and wait or partial allocation: The processes must hold the
they have already been allocated while waiting resources
for other (requested) resources. If the
__ Process had to release its resources when a new resource or resources were requ
ested,
Ae deadlock could not occur because the process would not prevent others from using
____ resources that it controlled.
j 3. No preemption: The processes must not have resources taken away while that
_ resource is being used. Otherwise, deadlock could not occur since the operating system
t 3 _ could simply take enough resources from running processes to enable any process to

a 4, Resource waiting or circular wait: A circular chain of processes, with each


__ process holding resources which are currently being requested by the next process in the
__ chain, cannot exist. If it does, the cycle theorem (which states that “a cycle in the
____ resource graph is necessary for deadlock to occur”) indicated that deadlock could occur.
ia Q.1.(c) What are various file attributes?
Ans: File attributes are settings associated with computer files that grant or
3 _ deny certain rights to how a user or the operating system can access that file. For
ae example, IBM compatible computers running MS-DOS or Microsoft Windows have
capabilities of having read, archive, system, and hidden attributes.
or
*Read-only - Allows a file to be read, but nothing can be written to the file
changed. — 3
a *Archive :Tells Windows Backup to backup the file.
¢ System - System file.
- Fil e wil l not be sh ow n wh en doi ng a reg ula r dir from DOS.
*Hidden
(d ) Ex pl ai n th e te rm ca ch in g an d bu ffering?
Q.1.
Ans: Buffering:
in to a re se rv ed ar ea of me mo ry (the buffer).
e Preloading da ta
12-2016 | By
s,s to
Sixth seme . % \ a
. It tem ¥ i Ster, Operating System
Speed ; p rar ily Stores input
S of two device » OT output
mpt to
* Buffer may be used in b and a slow disk drive Detter Match ¢
two pr | ‘ : : »P, University-(B.Tech)-AB Publisher
itSeen
1Si sent to another moving
process.in | iterer 4asl ete1s retrieved
Data is stored i frombetween
data one Processes or . Q.2.(b) Differentiate between logical file system and ph 2016-13
* With spoolin ar Ust h Physicalf;
queued on disk to be soiapleted Intan yee ee Usually comp] ] — rei ta
wae It Kanone
is most] >used fori
ie ce ea Lie aa
;
sometimes temporary Storage of 7
“te jobs |
; aa
Physi
Logical file :
manner ata that may be modified in g neat Cith, Re haeoie the portion of memory. i. Deau nat eden
“Seque... ss
contai ains the original data. -
Caching: “quent,
|
* Caching transparently stores data a in
j compo | defined access path.
=

et
|

request for that data can be served faster. poneey called Oneia » SO that fut, - . Aphysical file contains one record
; ;
for
l eaiat Sea iat record d formats.

ontain up to 32, |
|
* A ;
spécial hig h-speedndstor age mec han ism. It can ie athe. ae | 3 ae
Wai
main memory or an indepe ent high-speed storage device. €rved Sectigng | 4. If there is aloo; = 3. Can’t exist without PE |
e The data that is stored withi : a a logical file for a PF, the 4. If there is a logical filef ——_|
earli duns an e t ie in a cache might be values that have b il PF can’t be deleted until and unless LF can be deleted wiwithout edel eng
reti
ve Computes we delete the LF. the PF
Dj ay ate ae aa of original values that are stored elsewhere. E.g: Me
1S i ac ae , Web Caching(used in browser), Database Caching ete. ae Caching 5. CRTPF command is used to create 5. CRTLF command is usedio |
ey e i os purpose is to reduce accesses to the underlying slower storage | such creat such object. | object.
° | : : ——
= Q oie @ . i
ae ;
with 1000 cylinders, numbered 0 to 999, compute the - | Q.3.(a) Consider the following snapshot of a system.
of tracks the disk arms must move to satisfy the entire request i: Umber ,
queue. Assume the last request serviced was at track 345 and heaq f be disk ised oan Allocation Pee 5 on
towards track 0. The queue in FIFO order contains request for the tie AB CD A BC D ABCD
OWing : |
) 376.
° 23,87 4,692,345,475,105,
aca. :1 Perform the computation for th followin Pl 0012 OO 12 i FS 2E
scheduling algorithms- 3 | () P2 1000 L750
,\(@) FIFO | (2) SSTF (3) SCAN P3 1354 2356
(6) C-LOOK | 4 P4 0 6 3:2 0652
| (4) C-SCAN (5) LOOK

jAns: (1) FIFO - 2013 | ae P5 0014 0656


The tracks traveled to will be 345,123, 874, 692, 475, 105 and 376 making the wd Let the available number of resources be given by avail vector as (1, 9,2, 0)
distance 222+751+182+217+370+271=2013. | | ~@, Use banker's algorithm and answer.
a| 1.Find the contents of the matrix “NEED".
(2) SSTF - 1298 2. Is the system in a safe state?
The tracks traveled to will be 345, 376, 475, 692, 874, 123 and 105 making th 3. If a request from process P, for (0, 4, 2, 0)
arrives, Can it be granted
total distance 529+769=1298 , Rare (6)
) , a immediately?
(8) SCAN-1219
tra vel ed to will be 345 ,123, 105, 0, 376, 475, 692 and 874 mak ing a:the
The tracks . Need
A B Cc D
4 =12 19 Bi. 4 i :
total dis tan ce 345 +87
ae 0 0 0 0
(4) C-SCAN - 1967 | 4 ; 0
will be 345 ,12 3, 105, 0, 999, 874, 692, 475 and 970 maRI :
The tracks traveled to =| ey 0 0 2 |
ce 345 +99 9+6 23 =19 67
the tota l dis tan
: oe 0 0 2 :
(5) LOOK = 100 9
874 malaai y, 0 6 4 |
The tracks traveled to will be 345 , 123, 105, 376, 475 , 692 and
| a 2. Banker’s Algorithm
total distance 240+769=1009
Step 1:
(6) C-LOOK - 1507 Safety for ee | e
tra cks tra vel ed to will be 345 , 123, 105 , 874 , 692 , 475 and 376 eae
The
total/distance 240+769+498=1507 a Need, = (0,0, ;
= 14-2016 ) 4 a
|
7; a < Available r, Operating Syéten,
Sa
2 » 0,0, 0)
Process P, will tie ye (true)
Available = Abie | | IP. University-(B. Tech)-AB Publishe
oa (1, 5, 2, Q) + (O 0 i Allocation | . if need, S Available .

= & & o, 3, 2) » a) | . bce 4 5 z : = a 12, 12)}


Sian .
| eee 9 Will execute,
Safes |
Available = Available + Allocation
y for process Pp. | | = (2. 14, 12, 12) + (1, 0,0, 0)
Need, = (0, 7, 5, 0) | bee ale e = (3, 14, 12, 12)
ifneed, < Available eC 3. If a re
oinencd + om<P prPLP,
quest3 fr PP
iiff [(0, 7, 5, 0) ocess P, for (0, 4, 2, 0) arrives,
_immediately?
Process P < (1,5, 3/2); :
_-—| s-:
2 Must waj it. After alloca Sg
Step 3: | “ new available ovte d
ine (1; 1.664 request it will subtract from the available, So
Safety for Process P_- Step 1:
Need. = ( 3 ei . Safety for process P
if = 1, 0, 0, 2) | = Need, = (0, 0, 0,0) :
| ate < Available Sa : a If need, < Available
IT - : sae .
Pp. » 9,0, 2) < (1, 5, 3, 2)] (true) | i. if (0, 0, 0, 0) < (1, 1, 0, 0)] (true)
ocess P, will execy be 4 Process P, will execute.
Available = Available + Mose st Available = Available + Allocation
= (1, 5, 3, 2)+(1,3.5, 4) Val = (1, 1, 0,0) + (0, 0, 1, 2)
= (2, 8, 8, 6) ae < erusn
St
a eep 4: —
Sa—
fety for process P,
ety for process P; | | Need, = (0, 7, 5, 0)
need, = (0, 0, 2, 0) | | ie me ifneed, < Available
If need, < Available if (0, 7, 5, 0) <(1, 1, 1, 2)]
If [(0, 0, 2,0) < (2, 8, 8, 6)] Process P, must wait.
Process P, will execute. Step 3:
Available = Available + Allocation Safety for process P,
= (2, 8, 8, 6) + (0, 6, 3, 2) Reedy 08.8
if need, < Available
ne tee * if [(1, 0, 0, 2) < (1, 1, 1, 2)] (true)
Step 5: Process P, will execute. ene
Safety for process P; Available = Available+ Allocation
Need, =(0,6,4,2) — =(1, 1,1, 2)+(1,3,5,4)
if need, < Available = (2, 4, 6,6)
if [(0, 6, 4,2) < (2, 14, 11, 8)] Step 4: |
Safety for process P,
Process P, will execute.
“need, =(0, 0, 2, 0)
Available = Available + Allocation
Ifneed, < Available
= (2, 14, 11, 8) + (0, 0, 1, 4) If [(0, 0, 2,0) < (2,4, 6, 6))
= (2, 14, 12, 12) Process P, will execute.
Step 6: Available = Available + Allocati
on
Safety for process P,
need, = (0, 7, 5, 0)
Safety for
P rocegs
need, = (0, 7, 5, P,
0)
if need, < Available
FLO, 7, 5, 0) < (2,
Process P, w
1 9 10, 12)
ill execute. |
Available = Available +
Allocation
|
|
| |
= ‘2, 10, 10, 12) + (1, 9, 0, 0) |
= (3, 10, 10, 12) ae | i
Safety Sequence = <P, P;, P, P,, P,> | |
He n ce the n e w 3 }
obs P, e
S yste Mm state is oatse SO we can | ant the re
2. Direct Access: Direct access is bas
ed on a disk model of a file. For direct
raediately gr quest fy the file is viewed as a numbered access,
sequence of block or records. A direct-access file
arbitrary blocks to be read or written. allows
Q.3.(6) Explain various file After block 18 has been read, block 57 could be
allocati
|

on strategies next and then block 3. There are no restrictions on


the order of reading and writing for a
(i) Contiguous (ii) Linked _(iii) Indexed
| direct access file. Direct access files are of great use
Ans: (¢) Contiguous Allocation: @ amounts of information.
for intermediate access to large
With contiguous allocation, each file has
contiguous blocks on the disk. The loca to Occupy The file operations must be modified to include the block number as a param
tion of a file is defined by the disk address eter.
first block and its length. Both sequential of the
access and direct/Random access are Supporta)
It works like “read n’, where n is the block number rather than “read next”. Simila
rly, it
by the contiguous allocatio3 n. The disadvant writes with “write n” rather that “write next”.
age of contiguous allocation is thatPort ed
itis An alternative “approach retains “read next” and “write next”. it adds an operation
often difficult to find free space for a new file. Moreo
ver, one is often not sure of the spay “position file to n” where n is the block number. Then we would issue the command
required while creating a new file. The various methods adopted to find
space for a ney “position to n” and then “read next”.
file suffer from external fragmentation. All operating systems support both sequential and direct access for files. Some
(tt) Linked Allocation: In linked allocation, each file is a linked list of disk systems allow only sequential file access. Others allow only direct access. Some systems
blocks. The directory contains a pointer to the first and (optionally the last) block of the require that a file should be defined as sequential or direct when it is created. Such a
file. For example, a file of 5 blocks which starts at block 4, might continue at block’, file can be accessed only in a manner defined at the time of its declaration.
then biuck 16, block 10, and finally block 27. Each block contains a pointer to the ne 3. Other Access Methods: Other access methods can be built on top ofa aes
access method. These additional methods generally involve the construction of * ei
block and the last block contains a NIL pointer. The value -1 may be used for NIL m -
for a file. The index contains pointers to the various blocks. To find an —
differentiate it from block 0. e the index is searched first and the pointer is then used to access the file directly
With linked allocation, each directory entry has a pointer to 7 rie a | the desired entry.
the file. This pointer is initialized to nil (the end-of-list pointer a ie ee With a large file, the index itself may pmo in large to noe ant
empty file. A write to a file removes the first free block and writes to tha Thi pears
soluti on is to create an index for the inindex file. The primary ae :
e just index files that would point to the actual data items
new block is then linked to the end of the-file. To read a file, the pointers are Jl pointers to second ary
in de xe d seq uen tia l acc ess me th od : (I SA M) ba si aver Hl sit mast.
followed from block to block. For example, IBM’s ocks
ary ind ex. The sec ondary in
‘on: &
There is no external fragmentation with linked allocation. Any free b
e block can be4 index that points to dis k blo cks of a sec ond
s i z e o f a i i t
.
used to satisfy a request Notice also that there is no need to declare th e
7
|
—~ “aU LG =
, Sixt]
tot 1 Seme
dcigddae nm 3 blocks he file ; k re Operating System
© Master j 1S Kept sort
secondary
Containing index. This hy.)
any reug
th “US block jg24read8 partion
¢
Or a,
ar item. defined key.
It provides We first ma
© desired record the block ni.
'n. Binary search is used again to pmber“bin,
rd can be located f; Inally, this block is searched se uta
ap I.P. University—(B. Tech)-AB Publ
isher 2016-19
Q.4(b) xplain th rom its ey by at most direct access fendi
the be (v) The user can change his current dir
ectory whenever he desires.
“ally. Tn thig i (vi) Ifa file is not needed in the curr ent
Ans: There ar © variou directory structures? directory then the user usually must either
follows: “Many types 0 “ | specify a path name or change the curr
ent directory.
Paths can be of two types :-
(1) Single Level D
irectory (a) Absolute Path
(2) Two Level Dire Begins at root and follows a path down to the specifie
ctory d file.
(3) Tree Ce § Structur (b) Relative Path
ed Directory
(4) Acyclic Graph Di Defines a path from current directory.
rectory vii) Deletions if directory is empty, its entry in the directory that contains it can
(5) General Graph Direct
ory simply deleted. If it is not empty : One of the Two approaches can be taken :-
(1) Single Level Dire
ctory (a) User must delete all the files in the directory.
In Single Level Directo (b) If any sub directories exist, same procedure must be applied.
ry all files are in the sa me dire
Limitations of Single Le ctory, The UNIX rm command is used.
vel Directory
(a) Since all files are in the MS dos will not delete a directory unless it is empty.
same directory, they must ha

a
ve unique name (4) Acyclic Graph Directory
directori=es
ries : catal a } at,
Acyclic Gtaph is the graph with no| cycles. It allows directo
i
(c) Files are limited in length. and files: With'a shared file, only one actual file exists, so any
(d) Even a single user may find it difficult to reme mber person are immediately visible to the another.
the names of all file
number of file inc reases : s as} ' Inplememtation of Shared files and directories
| |
(i) To create a link
of yso many file | is daunting task.
trackctor
(e) Keeping Dire Alink is effectively a pointer to another
ile or sub os nga
(2) Two Level in both sharing
Duplicate all the information about them
(i) Each user has Its own User File Directory (UFD),.

oe
yf nena


ii) Dele ting a link
file, ie i

i
(ii) When the user job start or user log in, the system Master File Directory Mr eee of the link will not effec t the orig inal
is searched. MFD is indexed by user name or Account Number. | | “a to it are deleted.

=—
the file unti l all refe renc es
- - To preserve

me
(11) When user refers to a particular file, only his own UFD issearched. - 3.
N
Thus different users may have files with same name. To have a particular
uniquely, in a two level directory, we must give both the user name and file name,
A two level directory can be a tree or an inverted tree of height 2 ;
The root of a tree is Master File Directory (MFD). |
of i :a
Its direct descendents are User File Directory (UFD). The descendents
file themselves. | |
The files are the leaves of the tree.
es git sh
Limitations of Two Level Directori
ly iso lat es one use r tro :
The str uct ure effective
ry
(3) Tree Structured Directo
os
ir

e s a m e in te rn al pe ar
directories has th
y en tr y r d e a e
in each direct or
(i) One bit S aw aa l
ar e us ed to create and de
(ii) Sp ec ia l ca ll s d contain mos}?
curr ent di re ct or y. Cu rr en
nae rule process has a t to the process. ched.
(iv Aa
* hos a ref erence is made to a file, the current directory

~
ena
—a
LP. University-(B
Tech)-AB Publishe
r

Relocati-
ve questions includi
ng Q. No. ] which is on
| Q.1.(a) Compare multi compulso Mo, ,
Systems. -programmed Logical | 14000 | physical
batch CPU address 3 address ssl
a te , J
Systems
346
}
Ans Multi-programme
d S
and tim 14346 meer
:
:
3

While, the one-to-one mode


l maps each user thread to a kernel thr
Ans: System more concurrency than the ma ead. It provides
ny- to-one model by allowing another thread
a thread makes a blocking syst to run when
and execution. e m call; it also allows multiple threads to run
on multiprocessors. in parallel
(a) File modification: Several tex Q.1.() Mention the necessary condition for
t editors may be av a deadlock situation to arise.
the content of files stored on disk or ailab] € to creat
other stor age devices e and my |
(6) File management. These programs create dele . ;4
Ans: Necessary condition for deadlock are:-
(2)
, te,
list, and generally manipulate files and dir
*
a

ectories. _
copy, rename, ‘ . 8 A
(i) Mutual exclusion
Print, du
(c) Communications: These programs (ii) Hold and wait
provide the mechani iS]
connections among processes, users, sm for creating (iii) No preemption
and co mputer systems.

deVisgeualn,Bas
4d) Programming-languag (iv) Circular wait |
e support: Compilers, assemble
interpreters for common pr
ogramming languages (such
rs Q.1.(g) Compare FA32 and NTFS file systems.
as C, C++, Ja (2)
and PERL) are often provided to
the user with the operating system va, Ans: FAT32 is one of the most commonly used file systems around. Most Operating
Q.1.(c) Explain memory manageme . systems, including Windows 98+, OS X, Linux, support the FAT32 file system.
nt strategies. NTFS has lower support and has only read support in OS X.
Ans: Two basic memory management st : a
rategies are FAT32 does not support file compression, encryption and other functions supporte
¢ Paging . by NTFS.FAT32 has a upper limit of 2TB on Hard drives and a limit of 4GB on omer
files. NTFS on the other hand, has a limit of 16EB for both hard drives and single files.
° Segmentation
_ (1 EB or Exabyte = 1024 petabytes and 1 petabytes = 1024 terabyte).
Paging: Paging is a memory-management scheme that permits the physi Q.2.(a) Explain the features of parallel systems und distributed — 2
address space of a process to be non-contiguous. . 2

Segmentation: Segmentation is a memory-management scheme that supp Ans: Multiprocessor systems(also known as parallel systems or tightly ae
this user view of memory. A logical address space is a collection of segments. Bit systems) are growing in importance. Such systems have two or more processors im close
communication. Sharing the computer bus and sometimes the clock, memory, and
S egment has a name and a length. The addresses specify both the segment
t oe

eae
- a A
F =ae
peripheral devices.
the offset within the segment.
+ i

|
Se

ultiprocessor systems have three main advan : .


. ae

Q.1.(d) Explain the process between mapping of logical address 7 F a Increased throughput: By increasing the number of procs * awed &
physical address space. { :
get more work done in less time. When multiple processors coopera
Ans: The run-time mapping from virtual to physical addresses is done by a a
device called the memory-management unit (MMU).
| d to every addr
The value in the relocation register is adde by.aus | , quivalent
ess son bya at a. waaanctn of scale: Multiprocessor systems can cost gente tt
Process at the time it is sent to memory (see Figure). For example, fe mer. pee pe w a wu ceasets
multiple single -proce ssor system s, becaus e
> he 18)
be yy ae

‘4000, then an attempt by the user to address location 0 is dynamically re ocae" 3 :


and power supplies. If sever al programs opera |
1 ocation 14000; an access to location 346 is mapped to location 14346 e
ae
99-2016
Sixth Semester, Operating
System
store those data on one disk and to have al] the
many computers with local disks and mat processors share them than to , .
(c) Increased reliability: If Rinealaal ee a P ‘ nee meen er pie Ole
processors, then the failure of one BiGcke S can be distributed properly among Seven, Fig. Hardware support for relocation and limit registers.
If we have ten processors and one fails hie will not halt the BY stem, only Slow it do, a Q.2.(c) Explain the address generation in segmentation with paging. 4)
pick up a share of the work of the failed en each of the remaining nine proceggor, Ans: Segments can be of different lengths, so it is harder to find a place fo,
percent slower, rather than failing alto eo Thus, the entire system ruNS only | segment in memory than a page. With segmented virtual memory, we get the benefits a
Distributed Systems ogether. virtual memory but we still have to do dynamic storage allocation of physical memory.
| _ Inorder to avoid this, it is possible to combine segmentation and paging into a two.
A distributed system js > level virtual memory system. Each segment descriptor points to page table for that
computer syst
collection of physically separate, ; possibly heterogen, 4 Be aoa ‘ .
Noa kee ok a that are networked to provide the users with access to the varia segment. it gives tas a ua a paging (easy placement) with some of the
speed, functional; System maintains. Access to a shared resource increases computats advantages of segments (logical division of the program).
x lonality, data availability, and reliability. “On |
eeenet foe the simplest terms, is. a communicat se ion path | between two or mon | Page table for seg 0 rameo| "y
A - Uistributed systems depend on networking for their functionality, © Bm) re i,
| Such | | e20
= cee ati
operating . system that provides features
system is an operating ariel 4 rame | “J
:
: oe across the network and that includes a communication scheme thar Segment Table
he
= B literent processes on different computers to exchange messages. A compute, STE 0 frame 2\
ie & network operating system acts autonomously from all other computers op thas STE 1 ee
e Page 00
a | 4 STE 2 Page table for sea4 aarti 9 frames
Q.2.(b
coke * ) Compare contiguous versus non contiguous memory allocation STE 3
rcs es. } | (6) STE 4 frame 4 |
aT gee |
‘sms: The main memory must accommodate both the operating system and ‘i 4
various user processes. We therefore need to allocate the parts of the main memory | . frame 5
the most efficient way possible. This section explains one common method, contigu ag | | :
Ous .
memory allocation.
ts he | aa E page #: offset 45 21 6 rame
The memory is usually divided into two partitions: one for the resident Operating | seo 5 ;
system and one for the user processes. We can place the 0 ES oF aa ; 3 i
; . perating system in eith oi = 3 rer
ora ; _ Q,.3.(a) Explain any two page replacements algorithms. Give an pean
ine J. os high memory. The major factor affecting this decision is the location
sikee ee neat greed gee Netel is Soe low memory, programmers usually | | e = ae te pagent

ES sell Re
a Ans : FIFO Page Replacement:- The simplest page-repiacemen

into memory. When a page must be


user processes to reside in memory at the same time, Wg] tin, fiat ou: (EEO) alrite Nrought
ry as well.

cherlare saad ciant several


: lgorithm associates with
We usually want | ays : Aas a -j a

Me
thedpt mien waits cate available memory to the processes that are in pag : P to hold all es in memory.We
4 replaced, the oldest page is chosen. Create a FIFO queue 0 pag .
ing to be brought into memory. In this contiguous memo
each process is contained in a single contiguous section of memo - allocationyy replace the page at the head of the queue. When a page is brought into memory, we
‘ Contiguous memory allocation is a classical memory siodaenie del thatthat assigns a— insert it ak tie $ail:of the qneuns Tie SiO ene trea
is erg meee
; model
nie memory blocks (that is, memory blocks having consecutiv — arab phones Meee SS eee cee
sees a der frame size = 3
FIFO ii: g i
. xample,
enna
nge dynamicall y.
es ee
This flexibility is desirable
; .
1
in many aoperating-
an effective way to allow the
the operating system contains code and buffer space for device situations
drivers. For eg . payedenes seat
:
66. PO. 6.9 to OSG ee SS

limit] ffelocatio | C4 1 Ad Gee ome Oe ee Bee G8 BS St


register | register O22 34S 2 as ve 6G 62.26.38 63-1 WeG 2 4
$0 85S oR 6 bk C Wee a de Pea A
dare, *
logical
ogical
: ee eS
|
ee ae
CPU address physical | coNee* .
memory FIFO
Total 14 page faults.
* Least-recently-used (LRU) algorithm:
lac eme nt ass oci ate s wit h eac h pag e the tim e of that page’s last use. When
- LRU rep
cho ose s the pag e that has not bee n use d for the longes t
trap: addressing error a page must be replaced, LRU
can thi nk of this str ate gy as the opt ima l pag e-r epl ace ment algorithm
period of time. We es |
looking backward in time, rather tha n for war d.
e.g. efined by the time of last use
consider frame sive —
LRU: aT ;
Page reference stream:
2023 |
1 : : Baca 8 8-8 6. Ss 8 Or eagaae 3m
a O98 2 a8 2b 8 8. 18 ee Ans: The objective of multiprogramming is to have some pr runnin aa
Fg ce ce 1 6) 2718 88 1 8 6. times, to maximize CPU utilization. The dhjscive of time ivindsta td antics hace
+d e Pe 2a 6 8 6 6 818 6.1 a among processes so frequently that users can interact with each pro
gram while it is
* ‘ak * a ok Eo oa * .
running. To meet these objectives, the process scheduler selects an available process
LRU “on (possibly from a set of several available processes) for progra
m execution on the CPU
| | a For a single-processor system, there will never be more than one running process. If
Total 11 page faults. Ae there canto
are more processes, the rest willwill have to wait
EGR until the CPU isi free and can be } 424 j
Q.3.(6) Mention the cause that effect thrashing. How does degreeoat, {|
multiprogramming and CPU utilization effect tracing.
Scheduling Queues
Ans : If the number of frames allocated to a low-priority process falls below the 4 As processes enter the system, they are put into a job queue, which consi
minimum number required by the computer architecturewe sts of all
, must suspend that Procegg processes in the system. The processes that are residing in main memory and
are ready
execution. We should then page out its remaining pages, freeing all its allocated framarl and waiting to execute are kept on a list called the ready queue.
This provision introduces a swap-in, swap-out level of intermediate CPU scheduling ia Process state diagram
the process does not have the number of frames it needs to support pages in active us me r
it wills quickly page-fault. At this point, it must replace some page. uae o
alm, |

However, since all its pages are in active use, it must replace a page that will i z

es
ee
admitted interrupt
needed again right away. Consequently, it quickly faults again, and again, replacing
pages that it must bring back in immediately. This high paging activity is calla

oe
washing. A process is thrashing if it is spending more time paging than executing a

Juha,
Tie Ml Smee ty
di
o
i Oo

a. B
a 7
e
cE
So

>

ex
o
oO

hy
So
BS
ct
ne)

ry

es
©

S
@

-Q
mM
B
°
=
~

Den
he

o
»=cilization. If CPU utilization is too low,

Pin!
ahs Sa ~
utilization

I/O or event completion Yo See VO or event wait

be B68
f
‘We increase the degree of multi-

a
DS
= WF nse as
programming by introducing a new process

adh -
trashing
to the system. A global page-replacement
algorithm is used; it replaces pages Q.4.(a) Explain various type of inter-process communication. Give an
CPU

without regard to the process to which they

ee
illustrate for each. - (6)
belong. Now suppose that a process enters Ans: Cooperating processes require an inter-process communication (IPC)
a new phase in its execution and needs - mechanism that will allow them to exchange data and information. There are two
more frames. It starts faulting and taking fundamental models of inter-process communication: (1) shared memory and (2
frames away from other processes. These 3
degree of multiprogramming a message passing. :
processes need those pages, however, and so they also fault, taking In the shared-memory model, a region of memory that is shared by cooperating
frames from other!
processes. These faulting processes must use the paging device to swa p pages in an ia processes is established. Processes can then exchange information by reading and writing
data to the shared region. In the message passing model, communication takes place by
means of messages exchanged between the cooperating processes. .
Both of the models just discussed are common in operating systems, and many
systems implement both. Message passing is useful for exchanging smaller amounts of
data, because no conflicts need be avoided. Message passing is also easier to implement
than is shared memory for inter computer communication. Shared memory allows
maximum speed and convenience of communication, as it can be done at memory speeds
when within a computer. Shared memory is faster than message passing, as message-
passing systems are typically implemented using systein calls and thus require the
more time consuming task of kernel intervention.
y IER “ss

In contrast, in
Shared-
shared-memory
regions
as routine memo
ry
LE University—(B.Tech)}-AB
Publisher
T, and T, are executing the same operat 2016.
Process A ion wait(
& process A
.
Sidhiacs is not atomic and T, updates the valueS) simultaneously since the wa
updates(overwrite the value written by T.) the actual of S and at the same timal
L PhMetess B ~ Shared memory d |
but the simultaneo exe
usly cution causes decrement in only 4 Phin jeans value of § ,
| “process B. = race condition and this causes an inco : 2
ee tas pe ea acl ee ; as ia
has more resources available than it truly does. a a a thinking it
Q.5.(a) Consider the system consistin
g of m resources of the same ty
shared by n processes. Resources c an be re pe he;
quested and release by Proces
.
only one at a time. Show that the s ystem se
is deadlock
:

Message queue ~ a free if the following two


condition holds:
{Molmy lima ney ma} We eeha ee a (¢) The maximum need of each proces
s is between 1 and m resources. =
ES kemel He eee ne i (tt) The sum of all maximum needs is less tha
n m+n.
(a) Ans. Proof: Suppose N = Sum of all Need, A= Sum of all
(b) Max. Use contradi
Allocation, M = Sum of all
ction to prove.
eeiaa Message passing Shared memory aa
e e ; a Assume this system is not deadlock free. If there exists a deadlock state, then
bilisep:
. . he followi e
n
& processes arrive for execution at the time indi
. .) Clay. A = m because there’s only one kind of resource and resources can be requested
and
released only one at a time. From condition b, N+A=M<m-+#n. So we get N+ m<
m +n. So we get N <n. It shows that at least one process i that Need = 0. From condition
Process Arrival time Bursttime a, Pi can release at least 1 resource. So there are n-1 processes sharing m resources now
P 1 0.0 . 8 ‘a8
condition a and b still hold. Go on the argument, no process will wait permanently, $0
a
there’s no deadlock.
Q.5.(6) Write banker’s algorithm to decide whether the system is a safe
i. 1.0 1 I
_ state. (5)
Use non-pre-emptive to answer the following: Ans :The name was chosen because the algorithm could be used in a banking
; (i) What is the avera ge turnaround time for these processs with system to ensure that the bank never allocated its available cash in such a way that it }
scheduling? FOR could no longer satisfy the needs of all its customers.When, a new process enters the
system, it must declare the maximum number of instances of each resource type that it
_ (ii) What is the average turnaround time for the
i i roe
0 ae

se processs with cp
’ -

a may need. This number may not exceed the total number of resources in the system.
heduling? 1 *
si
e When a user requests a set of resources, the system must determine whether the
_ Ans: ({) For FCFS
an

- allocation of these resources will leave the system in a safe state. Ifit will, the resources
~ are allocated; otherwise, the process must wait until some other process releases enough
resources. Several data structures must be maintained to implement the
0-8. banker’salgorithm. These data structures encode the state of the resource-allocation
419-43 3 a 4
Turn around time for P= 8 system.
Turn around time for P,= (12-0.4)=11. a 5 Let n be the number of processes in the system and m be the number of resource
6 ; pty types. We need the following data structures:
Turn around time for P,=(13-1)=12 2 a :
, e Available. A vector of length m indicates the number of available resources of each
Avg=(8+11.6+12)/3=1 0.533
unit. type. If Available [j] equals k, there are k instances of resource type Ri available.
(tt) For SJF
¢ Max. Ann x m matrix defines the maximum demand of each process. If Max\ilj]
equals k, then process Pi may request at most & instances of resource type. _
L2 1 BTR TR Le ¢ Allocation. An n xin matrix defines the number of resources of each type currently
0 04 10 2.0 5.4 183
allocated to each process. If Allocation{i][j] equals k, then process Pi is currently allocated
Turn around time for P,=(13 k instances of resource type . :
— 0.0)=13
Turn around time for Po=(
5.4 —0.4)=5 ¢ Need. Ann x m matrix indicates the remaining resource need of each process. If.
Turn around time for P,=( Need{il[j] equals k, then process Pi- may need k more instances of resource type R- to
2.0 -1.0)=1
on (13+5+1)/3=6.33 unit complete its task. Note that Need [i]lj] equals Max [i]j] Allocation{il)).
automaA.ti(cca
) ll§y 1, case if0 tithee waiteons Safety Algorithm
and signal oper| ation are no We can now present the algorithm for finding out whether or not a
system is ina
pr oc es s t executeted — ows: a ere
se Violated. s ynchronization), then mutua safe stat e. This alg ori thm can be des cri bed , as foll
l exclusive may be
len gth in and n, resp ecti vely. Initialize Work =
ens © : wai
Lett(Sus) wait(S) ( while (S <a | — 1. Let Wor k and Fini sh be vect ors of
}
0) ;/busy waitS--} Available and Finish [i] - false for i-0,1,...,n-
operation is not atomi "a a
d ¢1.€ all operation inside wait(S) are not executed 2. Find an/ such that both
(a) Finish [i] ==false
“~ Go to Step 2 LP. University—(B.Tech}-AB Pu
blisher
4. If Fin; Al; * One reason is to cope with a spee
2016-29
esource-R. t] d mismatch between the producer
“dest— Al true for all, s then the
Wa. of a data stream. and consumer
gorithm system is in a 8afe
state e Asecond use of buffering is to ada
éTanted L W d e s crib pt between devices that have different data-
et Reques e the transfer sizes
t; be ther * Athird use of buffering is to support copy semant
ics for application I/O.
If Regues; t [7] C=-c hiA cac
ng he is a region of fast memory that holds copies
request for re of data. Access to the
cached copy is more efficient than access to the original. For ins
tance, the instructions
of the currently running process are stored on disk, cached in physic
al memory, and
copied again in-the CPU’s secondary and primary caches. The difference between 3
buffer and a cache is that a buffer may hold the only existing copy of a data item,
whereas a cache, by definition, just holds a copy on faster storage of an item that
2. If Requesti< Availabl resides elsewhere.
e go to step 3
Otherwise, Ps must Q.6.(c) Explain the recovery technique used in deadlock. (4)
wait, since the resource
3. H: ave the system s are not avai Ans. Recovery from Deadlock
pr et en d to lable.
by modifying the state as foll ha ve al lo ca ted the requeste When a detection algorithm determines that a deadlock exists, several Serer
ows: d res ources to Process : ;
are available. One possibility is to inform the operator that a deadlock has a i’ s
Available = Available-Requesti; a to let the operator deal with the deadlock manually. Another ee at ae fat
Allocation = Allocationi + Requesti; system recover from the deadlock automatically. There are two options = SiS - ;
Needi = Needi—-Requesti; deadlock. One is simply to abort one or more processes to break the circular :
| | | = other is to pre-empt some resources from one or more of the deadlocked processes.
(a) Process Termination
To eliminate deadlocks by aborting a process, we use one of two ee
methods, the system reclaims all resources allocated to the nae Se a
e Abort all deadlocked processes. This method clearly will bre kak Ga alan
are shared by three Processes, cycle, but at great expense; the deadlocked processes sik ep tata tank ockalls
that the system is deadlock-free. time, and the results of oe partial computations must be
. ater. : let
ae are R1,R2,R3,R4 processes .let us consida, ie ee REL pA ISS at a time until the deadlock cycle ae heey
s R1 ,P2 holds R2 andpyder
and pr
20lds R3.R4 is free .Ever i ethod incurs considerable overhead, since, after each process 1s abo ee
‘ detected algorithm must be invoked to determine whether any pr
deadlocked. 600
; tion é | . £ ome

= Taian: using resource Ey nee Inaseamnnly ee tack


ses and give these resources to othe pce teases
Q.6.(a) Explain the following disk eee ae is required to deal with deadlocks, then |
scheduling algorithms. A otek
Ans. (i) FCFS Scheduling: The simplest form of disk scheduling (6)
first-come, first-served (FCFS) algorithm.
This algorith
is, of co urse , the
need to be addressed:
1 i
cea
ee
ictim: to some
ae Minimi safe state, restar
t process = aig ati et
generally does not provide the fastest servic m is intrinsically fair, but it
e. |
(tt) The SSTF algorithm: Selects the ie ae ; Starvation: Same process may always be picked asvictim,
request with the minimum seek time from rollback in cost factor.
the current head position. Sine e seek | (3x5=15)
time increases with the number of cylinder 4
traversed by the head, SSTF ch ooses the pending request closest to the current head“7— 0.7, Write or iirector
ory
y syste
syste
m _(b) File organ
;
isati on tech niqu e
(a) Two ee sys :
(a) Data intogrity panne |
position.
vi) C-SCAN: Like SCAN, C-SCAN moves the head from one end of the disk to the pec tain multilevel feedback queue aqpedyling: ae a es, clay
othe r, servicing requests along the way. When the head reaches the other end, however, —
it immediat

~ s: (a es level direc ;
tory system: ee ae structures, but each
ely returns to the begi nning of the disk, without servicing any reques tory (LTD). The
: S hav | . _ the system ’s
1n
%

the return trip ts on Myj sea t When a user job starts or a user logs
ee i “file ‘ of sam
lists only the file
Q.6.(6) Explain the role of c atching and buffering used in devic
manageme { UF tu
an when the users are
ive attributes. ints to the UFD for =
“_ ee ee a another. Isolation 1s gore sn eaaanateiett
ane
— oh at but is a disadvantage when the
ee tely indep
sumuill done for three reasons. one another’s
>
files ;
ea to access
VU—2UL0 OLALTL vemester, Operating System
ique: Tb provide efficient ant
disk, the operating system irncbas ce . file ayat aha to allow wt C886 ty
ees Sree co Sue easily.
oe oaiban Wi eat 0 ac is defi ning Ahow
file system poses two quite differ vata ton
the file system should look to thers esi,
sera day so aaa a & file and its attributes, the operations allowed on a file The
ate seraikinhes = ean chia files. The second problem is creating algorith
4 the
eee P the logical file system onto the physical Secondary.gt ang.
Tap,
ane file system itself is generally com posed of
. .

many different levels. oa


°

(i) Application programs (ii) Logical file system |


(i) File-organization module (iv) Basic file system
(v) I/O control devices
(c) File access control: Different users may need
differ
or directory. The most general scheme to implement identient types of accegg
ty dependent acceas Tam maintain
associate with each file and directory an access-control list (ACL) spe
| than user threads
cifying seg
as the
ty
y must be r epresented
with
and the types of access allowed for each user.
a k eT nel data

| "athe
When a user requests access to a particular file, the operating system checks
access list associated with that file. If that user is listed for the requested accep 8 the
access is allowed. Otherwise, a protection violation occurs, and the user job ig ea
access to the file. | “Tiley
proces s: Data integri ty refers to the accurac y and consists ‘
(d) Data integr ity
of datastored in a database, data warehouse, data mart or other construct. The tend
_ Data Integrity - can be used to describe a state, a process or a function — andj, aft
used as a proxy for data quality , se ty
(e) Explain multilevel feedback queue scheduling. Give applicatio,.
Normally, when the multilevel queue scheduling algorithm is used, proceggeg ,"
permanently assigned to a queue when they enter the system. If there are sepa...
queues for foreground and background processes, for example, processes do no
from one queue to the other, since processes do not change their foreground or bac Dung.
nature. This setup has the advantage of low scheduling overhead, but it is inflexible —
The multilevel feedback-queue scheduling algorithm, in contrast, allows,
process to move between queues. The idea is to separate processes according to the Ana. The address generated by CPU is logical address. Log
characteristics of their CPU | —— ical address is generated
when instruction or data are executed. During its processing
bursts. If a process uses too ee ee by CPU it generate some
As address for allocating some space in memory. This address is known as logi
much CPU time, it will be = 8
quantum cal address.
moved to a lower-priority NE CREATE OOS Ea aie g The address generated by memory unit: to load the instruction and data in
to
queue. This scheme leaves I/ 2 memory register is known as physical address.
O-bound and interactive : emma wisi scr ait _ |
processes in the higher- eee “quantum = 16. a > Physical address is used in main memory where as logical address is used in
priority queues. In addition, Lenni virtual memory.
a process chat waits too long Physical address is divided into small parts called frames and logical address is
in a lower-priority queue
divided into small parts called pages. |
may be moved to a higher-
= Priority queue. This form of Logical address (virtual address) refers to a memory location independent of the
aging prevents starvation. current assignment of data to memory
_ For example, consider a multilevel feedback-queue scheduler with three queues, : Physical address (absolute address) the absolute location of unit of data in
| pein from 0 to 2. The scheduler first executes all processes in queue 0. Only |
when memory’
a ot : empty will it execute processes in queue 1. Similarly, processes in queues
> © executed if queues 0 and 1 are empty. A process that arrives for A logical address is generated by the CPU and is translated into a physical
queue 1 will
queue 2. A process in queue 1 will in turn be pre-empted
by# address by the memory. management unit (MMU). Thus, Physical Addresses are
8 arriving for queue 0. generated by the MMU.
/ Vv
EEE NI PCL AUALIE, WY SUCIT)
Q.4. 4. GiGiven mem
ory partition
(in order). H of 100 KB, 500 K
* ow would e B, 200 Kp, 300
| e fi‘nrsott fifit,
ach of th
v “e Process of 212 KB bes t fit and Worst An q
f0rithm makes the mo
, 417
KB, 112 KB and 426 KR

*j
st efficient use of mem (in 5

a
ory? | “tery
Ans. (i) First-Fit |
212- KB_500
417 KB_600 KR
KR 100 KB, 288 KB, 200 KB, 300 KBV, 699,
100 KB, 288 KB, 200 KB, 300 KB, 1g3 pp

<a
112 KB_288 KB
100 KB, 176 KB, 200 KB, 300 KB, 183
426 KB_Wait (no partition KR
is large enough) 100 KB, 176
(ii) Best-fit KB, 200 KB, 300
: oS Se
a
212 KB_300 KR 100 KB, 500 KB, 200 KB, 88 KB, 600 Kp ; (FCFS)
417 KB_500 KB 100 KB, 83 KB, 200 KB, 88 KB, 600 Kp algorithm, in whicish ph
acenomenon latded wi with the e Fj
associate
hole Operating System slow First Come First
112 KB_200 KB processes. s down due to fe W i
100 KB, 83 KB, 88 KB, 88. KB, 600 kp FCFS algorithm is non-
Slow
426 KB_600-KB 100 KB, 83 KB, 88 KB, 88 KB, allocated toa process, other
preemp tive
in nature, that is, once CPU
174 KB time has beaca
= processes can get CPU time only afte' r the Current proces
(tzi) Worst-fit has finished. This property
of FCFS scheduling leads to th s
, Cea Effect. e situation called Convoy
212 KB_600 KB 100 KB, 500 KB, 200 KB, 300 KB, 38g Kp Suppose there is one CPU intensiv
417 KB 500 kB 100 KB, 83 KB, 200 KB, 300 KB, 388 Kp and several other processes
e (large burst
with relatively less burst
time) process in the ready queue

112 KB_388 KB 100 KB, 83 KB, 200 KB, 300 KB, 276 KR a. bound (Need I/O operations freq
uently).
times but are Input/Output (UO)

426 KB_Wait (no partition is large enough


CS The following then takes pl
ace -
) 100 KB, 83.KB, 200 KB, 300. Ky * The I/O bound processes are first: allocated
Best-fit algorithm makes the most efficient use CPU time. As th ey are less CPU
of memory. It is the oni ane intensi ve, the quickly get executed and then goto I/O
queues.
capable of meeting all memory reques ¢ Now, the CPU intensive process is allocated CPU
ts in this case. time. As its burst time js
: melhy, 0 high, it takes time to complete.
ey f a
|
While the CPU intensive process is being executed, the I/O
bound processes
comple te their I/O operations and are moved back to ready que
ue.
* However, the I/O bound processes are made to wait as the
CPU intensive process
still hasn’t finished. This leads to I/O devices being idle.
|
¢ When the CPU intensive process gets over, it is sent to the
I/O queue so that it
ean access and I/O device.
© Meanwhile , the I/O bound processes get their required CPU time and move back
to I/O queue.
° However, they are made to wait because the CPU intensive process is still
accessing an I/O device. As a result, the CPU is sitting idle now.
Hence in Convoy Effect, one slow process slows down the performance of the entire
set of processes, and leads to wastage of CPU time and other devices. -
To avoid Convoy.Effect, preemptive scheduling algorithms like Round Robin
Scheduling can be used — as the smaller processes don’t have to wait much for CPU time
— making their execution faster and leading to less resources sitting idle.
Q.1.(b)What is batch operating system. Explain . | (2.5)
Ans. The main function of a batch processing system is to automatically keep
executing the jobs in a batch. This is the important task of a batch processing system
i.e. performed by the ‘Batch Monitor’ resided in the low end of main memory.
hnique was possible due to the invention of har d-disk drives and card :
ee ‘ e the jobs mio be stored on the disk to create oe ats hE iy a
and executed by ee
executi-on as a batch. First the: poo led jobs are readEE the ba chm
iobs are grouped; placing the identical jobs Jo a
Shee ee So, _ the batch processing system, the batched jobs wer neue
automatically one after another saving its time by performing the activities (like loa ing
around time y for o nee, [t resulted '
in improved system
utilization du tog
In the early ;
spat
io aciee a wadn s i, “au
+ labhidlee inin t 6
thh e e
maunin
e Sy
mest
moem
rys, tha ejobjobs were placed in jo
ae “to memory. Once was selected from the bjo 1.P. University-[B ‘Tech.|-AB
Publisher
ve $01 When the the job loaded into Sue 2017_9%
pr oc es so r primary MEMOrY, it When a Process Change his State fr
a0 was loaded in be ca me available, the Pr o¢ au om o ne State to Another, then
as the Process State Transition. In this » AT this is al. SO
the memory and ocessor scheq ete UNMINg pr calleq
ocess may goes on Wait
execute it. and 4
| In batch ' Strategy ig j ne
approach files of th SY 1S implemented to provide a batch fil Running State.
e similar batch ar e Procegg; . Q.1. (d) What is Belady’s Anomaly.
e processed to speed
Q.1. (e) Explain variou up the task. ng. “ing Ans. In computer storage, Belad y’s anomaly (2.5)
s states of a process. proves that it is possible to
more page faults when increasing the number of page fra
Ans. A Process whic a ’ mes while using the F
have
h is e ISt in
First Out (FIFO) page replacement algorithm. Laszlo Belady demonstrated this in
| 1969.
In common computer memory management, ere is loaded = —— —_
unks., Each chunk isi referred to as a page. The central processor y load a
fasted number of pages at a time. It requires a frame for each page it can load. A page
fault occurs when a page isI not found, and might need to be loaded from disk inty
memory.
When a page fault occurs and all frames are in use, oe vere Ee . —
oom for the new page. A simple algorithm is patentee male on danas
fr es the longest is the one that is cleared. Until Be a sn euui alwaga Gs
1
iis believed that an increase in the number of page
.
fram
same number or fewer page faults. 7
; al le d FIFO anomaly. Usually, on es allocated
Itis also ¢ al memory, m e re aa ng a
the process execution a
is faster, rs e fuoedand page faults
0 ee aa Sie vatited happens, i.e., the exec as éten when
ution time pera is teased
emo
eere Aadhaaee Ween to the process. This is Belady’s Anomaly.
rtain page reference patterns. ‘ alti Proceasiug aud
a Q ‘. (a) Differentiate between Multi Programming,M
Multi Tasking OS. S))
ming system there are one or more
Ans. Multiprogramming: In eae cars
ded in main memory which are . re: to execute. Only one ee 8
prog :
tions (i.e., there isis a at most one
‘me ramm
time s is
able to get the CPU for exec
isi hile utin
all gtheitsothe
inst
rsrucare waitae ing
ng theiri turn.a
the system) while a woe 5
Peer ee fe: of i Se CPU time. Indeed,
The main i ie ate ng is to Ee
then this is called as the Wa Waiting for Some Input and Outp i s okie by definition,
iting Stat e. And in this ut Operatic suppose the pres runn ing process is p perf ormi ng an interruptnt thatthat p process
instead the Process is Stor process is not unde to be accomplished). Then, the OS, 2
ed out of Memory and wh aie that are ready to
then this will] Again be on en the user will p oe the control to one of the other el Zoni oPeY nee is wasted by the
ready State. and give the hea:
itchi ng).
(4) Ready State : When the Pr
ocess is Ready to Execute but
execute (i.e. process a ee Ina, this and way, No‘ing iabaiens keeps executing unti
a runn ia Thee
CPU to Execute then this is he is waiting for the waiting for the vO Bare ases the CPU
called as the Ready State. Af or when it blocks elles taas as long
+ Input and outputs the Proc ter the Completion of the as there are
es s will be on Ready State emery Mr ce dra ie is to keep the CP
the processor to Execute. means the Process will: Wait a
for the ee OS must be able to
progeserey <a such a system to function properly, ne provide the required
Note that in orde r aint separate areas of the main
load mult
modified by another one. Other
iple
tion to prog
avoiran’s iechan ce of one process being moe
d the d when having multiple le p
programs in memory 1s
:
Erased t
need to be addr esse d w
that needs to
problems that n ams enter or leave the mal in memo fit
ry. Another issue
at once in memory whic
tha Weare
fragmentation asLapras large programs may not 7
Lis
be handled as; we ‘ng and virtual memory. :
solved by using pasins es re fers to ex ecuting multiple
g : M u l t i p rocessing sometim hardwar e
Mu lt ip ro ce ss i n fers to the
e time. In fact, multipro ee If the underlying
processes (programs) at shan ts software (1.e., Stee is multiprocessing.
then tha Several
ont) aes
the CPU rovides
(i.e., than one processor
va
hardware provi more |
ra ti ng Systems
4-2017 ,
» Semester Ope
eed ltiple cores 0
nwibale .P. University-[B.Tech.]|-AB Publisher 2017-5
variations on the basic scheme exist, pe or mult; |
Lath 'P le digg. ,
p p p P
Sue package or multiple packages 1n on® * mmed by having multipj).
P P P P P
a s 1] Fal [4] 14) 14) 14) 18)
Anyway, a system can be both multip Ans Hale more than one plivet
as (iii) _ Initially > 2
LS) lL] Le
Tunning at the same time and multiprocessing DY 2 2 2 2| |6 6 6
| é aning of multipro a “8q, Soy re ae
Multitasking: Multitasking has the nitetle (programs, firocebsea quan 3 a 3 1 4 : : :
in, 1 FoF te 2 1
~_ore general sense, as it refers to having mu AGAEEh operating S 6 2 1
‘Tunning at the same time. This term is used 1n m CPU systems in threay
tasks share a common processing resource (e.g., and Memory), A ii mult. ) -P
Apne
eu » A C any time Pe gag? pee Ee = - 2
CPU is executing one task only while other tasks 1 ee eos 7| |7 2 2
2
al aes 5 ae cae The lug; aN 2
Parallelism is achiev ed when the CPU is reassigne 3 LOZ 3 3 3 3 3
thread context switching). or VASK (ie: Proces. -
7 hol - a| [2 6 6 6 1 A
ne a q :
'
4 task in a multitasking operating system 1si no t a whole applicatj
. : : Fug 3 2 1
e Catlon Droge (ae 2 3 S
it can also refer to a “thread of execution” when one proces ing three frames by LRU
Each smaller task does not hijack the CPU until s is divided into sub et
it finishes Te
multiprogramming but rather a fair share amount of the CPU time like jin thé sem : p p
called quan ie | | P E os = “ ; 4 4 4 4
Just to make it easy to remember, both multiprogramming
Operating systems are (CPU) time sharing systems. and multipage ~~ (iv) _ Initially 1
However, while & 1 1 : 5 5 5 > 2
multiprogramming (older OSs) one program as a whole keeps running | Empty 2 2 oe ;
2
= é -
until ; t block ou 3 3
multitasking (modern OSs) time sharing is best manifested because 3 5
each rm, Sn | 4
Process takes only a fair quantum of the CPU time. 4 o 4) 46 6
3 waning , 4 2
_Q-2. (b) Consider there are 3 frame allocated to a process and the 3 4 2 1 9 6 2 1
String is:1, 2, 3, 4, refers ane
2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6. Calculate
the number of “Reel
ee 6 Poe |
initially empty.
é aults for the following page replacement algorithms, assuming
all] framse t
——
1 4 4 6 é [S|
ee :
22
LSI | 6| 6
eee
[S|

(i) LRU (ii) FIFO (iii)Optimal |
== fe
a Bl
ee ats
' Ans. LRU replacement: _
skal babepste pat bal [3 3} |3) {3
ran ‘a ft 6 6F EZ eb €} nee ee 1 °F
| ie , aa :
1
34 Bhan Goi Be Rca. Py yt: . 6
ges Pp 5 aan a So ee 6 7 3 2 1 2 3
@ [J 4] [2] 3} [4] [2 iat 5 [6] [2] Gy -_ Assuming four frames by LRU
ON AB Bi SPARSE Bi age oge so 7 adie Pip
Emply pis Re Bh :
eS 9 eaile A 5 hes ae (initially Fhe ke Le be ns 1] fal fal fa] fa) fa
PPO pl a E may ) 2} | [2-
f2--t2i 2 21 12'-12t
[2] o7A7 6] [3] 2] a me 3}
121 }2 2
Oe 8 eae Bat. [3] {3 SI 6 Al is S$
se Direc wa |
3 t sabe aa fa] (a SEES
a ae ! Dae Be PSP ES) 14) LS!
Assuming one frames by LRU | a Ese
SP 1S) 1S} (5) 15 {s
OE Tae tg Ge eek ok OS
# A PIR BE gy
:
; ;
(Z) Initially P P Pp P
: z
1 1 3 3 > m5] rs aT yee
Empty 1 1 1 1|.14])
Yidid Ag) Ign ey [4}) fA 1]
4. 12 2| 12] {2) {2 2 | 2]
Sch aen ick Bi ira ee 6/ 16} |/6] |6] 16 [6}) {6 6
: a the ois 3] 13]
PR Pep Ls! [3| Es} [3] fs) [s}-
p i TE tl Pee be
| 2 EP ad Ey -
71 7| |7\
7 Ging 2 1
a) 13 6) [el Fy =
4M 6
2 3 7 6 ; | a Assuming five frames by LRU
2 1 3
. 2
Assuming Wo frames
by LRU
el er aoe
cee
2017-7

ofojolsl= ; aa
pferele am )woln
jo}
|
aa7a
oy *
; | 9 :
<T (|\ ” ele
-J i”
:
12
p 2 ae
a (o oOo al<-
<Pele
| a ro ] Te)
fo[s
i ora
:
SI wO\N| NS WL
ofofei7le

ae :
Ou.
f ®
offi)” :
E
AB Publiissnheer

icles"
Pp

:
Eafe 1 ™N o.{a ”
oD, (Taeleore!
|*4
2 3 55oc
| Se ined
nN
oy*
® :© © |
eo
afarn[ nse |
t“ c A x
.
a\st ees
h.

C B af-[alo1_)
@
orr e
wye
versity-(B.Tec

sii ao
ie seer alr|O)°? o
£3° :
o saitig flcis}° :
=[alo|?
£See | ‘J
63 elHl\N 1 a afol
e s|e “|
eae, E;
:a[-[s
d
io
v =
:
1 1
[.P. Uni

off = a[s|<|>
Lae
zi =
=
al AN}
ale]|e [>
| :
|
a7
x a
:= wi
|

z &
|

ZZ
a
ge .
Initially

£ w
é~
3
3
ss 7
i
al
. = :
4
——_ enteey?
mama
-.
(it)

=
_ [H[N[e[z]o]o
[R]
=[N]o[=]e]o ©
KENPO; s[oO;o: ; fa
oO
~“I1NIO[n [MO]
elalols [wl ol] o
e
Oe NL SteLee Sadc aie aoe
| w D>
TINIMiztiwlolrn alwlw

Assuming one frames by FIFO


S c7
ieee l
e 3 ee
~[oalelelolelo
“a
s |oe >Se ) | |
[-]alols =
SIS |
SO) oo
ee
B fal
: 8
T“]AN{ oO] zfwololnia
2 S3 3 oli<—
S INniols
i
=
|
3 LInin
S
2
~
o [al
n n}o|o
ole a; : “1812 [*[efolet o-§ alel~<
: =
oe
oa
, “EEE
a : _ Elstej<[ofels] 0 -
§ Bc rao
ee
:
ch oO
* = o “NIM [ ST {wl o o <
el qa Qi] e
ee: | :1
v
a
ga
Initially
Empty

; =
£ iw
oe a
(wz)

© =w
Pry
6-2017

_
; =
: a
N
=
I.P. University—(B.Tech.|—-AB Publisher 2017-9

No. of Number of page Faults


Frames LRU FIFO
One 20 20
Two 18 18
(vi) 15 17
Three
Four 10 14

.
re Five 08 10
2] Six 07 : 10
| 3 Seven 07 O7

| = (iii) Optimal
2 3 4 ; 6 | initial 4 ; 4 2 { 5 6 2 1 2

: e < Peete este:


2), 2), SHH
2), 2), 2), 2} [2
1a)2] Tad:
foe Pape GIN Fe PS 4 4 5 6 6\\6 5|
3 4
3 2 2 2] - c PL
- RNbee ES 2 3
SP gt Te cal fe ec Fa eS Cg
iat al fa Ee) Be ote Go Sed +4
SiESTP Stes Sipsietieies
>} 5] [sl fel fey fa EY EY ZL 2 ti 2
Sher lis ZPETULTALSLE QPEL
6
Ue, pS Shs SPECIES IUcecIC Shee at tse:
F P P
227,44
Assuming six frames by FIFO Total no. of page faults = 11.
P Pp p ye: —Q.3. (a) Explain various scheduling queues and scheduler in process
& és
(vii) _ Initially et Neale 5 P P Pp scheduling. (3)
Empty |. | | ts 7 > 4 1 tis ; Ans. The process scheduling is the activity of the process manager that handles the
. ‘ 3 ; 2 2 2 2 > removal of the running process from the CPU and the selection of another process on the
3 3 ) 5 basis of a particular strategy.
4 4 4] [4 y : | Process scheduling is an essential part of a Multiprogramming operating systems.
5]: fs | ' Such operating systems allow more than one process to be loaded into the executable
= 8 4 memory at a time and the loaded process shares the CPU using time multiplexing.
: = GS] [6 ‘ Process Scheduling Queues —
L_]
NS SQ Sa Ao oo aes . The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a
the same
Pp 6 2 4 separate queue for each of the process states and PCBs of all processes in
state are placed in the same queue. When the state of a process is changed, its"
1 | | . { executio n
1 1 1 { queue and moved to its new state queue. |
1 j PCB is unlinked from its current
2 oN D > 5 1 1 ng
3 3 <. : ; ae ; The Operating System maintains the following important process scheduli
3 3 3
3 } queues. |
4 4 oat Lass |
queue keeps all the processes in the eystem.
io j -« Job queue— This
4 zi memory,
2 9 3 : :
S
:
Sf fS yf . ¢ Ready queue- This queue keeps a set of all processes residing in main
6] ry
6 6
5 6 6] [6] |6 q ready and waiting to execute. A new process is always put in this queue.
The processe s which are blocked due to unavaila bility of an
L7| S « Device queues-
1 3 e 7 [7]
3 7 6 3 2 1 P | 1/O device constitute this queue.
Priority,
Assuming sevan frames by FIFO —
The OS can use different policies to manage each queue (FIFO, Round Robin,y and run
read
etc.). The OS scheduler determines how to move processes between the
|
| queues which can onl y hav e one ent ry per pro ces sor cor e on the system; in the above
diagram, it has been merged with the CPU.
Publisher
L.P. University-[B.Tech.}-AB

At | BT | CT | TAT wt
Process |

3 10 | 16} 13 3
A
Exit 5s | 4
> ¢ borlLe }
Cc 4 | o2| 19) 15 | ‘13
D 3 | a1} 17 | 14 | 13
E o |o}5 | 5-10

SRTF: [Z| Bl z\D\c\z


0123469
Process | AT | BT | CT | TAT wit

A 3 10} 19} 16 6
B ‘ 1 2 1 0
n through the process (2)
track of which ins truc
tion to execute next,
code with its Wn
C 4 4.a.,6 2 | 0
king variables, a nd a stack wh 5 y s t e m reo. terg D $ bt 4 b1 0
i ch contains the
oe tion Ee tfjois\ioao\}o}l4
PR: (TQ = 3ms)

| E[Be|Alp\cl A | 6:9 .10 2 19


® 3-6

Process | AT | BT | CT | TAT| wT
A 3 10} 19} 16 | 6

B 4-e-be 1-3 4:2


Q.3. (c) Consider t
time in milliseconds. Cc 4 ¥2 | 12)8 |} 6
6
65) D 3 1 10\ 7
Process Arrival Time Burst Time Boe Ot ont S184
A 3 th at it satisfies all the -
1 algorith m.Prov e
B 1 Q.4. (a) Explain bakery
i section problems.
C 4 requirements for critical | ae
2 Examination 20 16
D 3 Ans. Refer Q4(a) First term ample.
E -
1
ai n ra ce co nd it io n wi th suitable ex
0 a) Q.4. (b) Ex pl
am inat
in at ion
io n 2016 i
Qi(e ) Fir st Te rm Ex sizes =
Draw the Gantt chart & find: Ans. Refer different time quantum
ntage is there in ban
Q.4. (c) Wh at adva .
(t) Average waiting time for these processes sys e | ™.

el queueing
a

with the Shortest Ramateial 3 mu ltil ev


.

di ff er en t le ve ls of a e ee
Time First, Round Robin (Time quantum = ser vic ing , for ne
3 ms) & FCFS scheduling algorithm. _
s. Pr oc es se s wh ic h ne ed more frequent = ee ae
(ti) Average turnaround ti me for these processes An ti me qu an tu m.
with the SRTF, Round 3 s, ca n be in a qu eu e with a small
Robin & FCFS Algorithms. such as edi tor
eu e wi th a lar ger ee e = oe ee
a qu
for frequent servicing can be in sing, making more efficien
es to co mp le te the proces
TAT = CT
- AT swit ch

WT = TA-TBT

E|\|B|. A D.|C
Si -6 16 17 19
Publisher 2017-13
LP University-(B.Tech,.|-AB
; any f
TLBs can , r performance
suffe issues Ititasking and code errors. This
+!
Question from . ft © questi 28 inely; from mu by an ongoing
formance degradation is called a cache thrash. Cache thrash is caused by idk ta
each unit uding Q. No. 1 Wiii
wh ch igs compu]
Q. ay Answer th follow;
t}) och . ity that fails to progress due
computer activ to excessive use of resources or co
Sory Se Ct | the caching system.
Q.1. (a) What d “ng short answer questions: " Q.1. (e) What is the utility of cache memory in the system 9-
}
(2.5)
An 0 you mean b . RAM)
= Context Switchin Cach also called CPU memory, is random access memory (
one Switching ? t caaimulae made aden ia access more quickly than it can access regular
is the: swj
ee tching oftch
the (a]GE some
; vefi niti
time s on:
referred to as a Process Switch o (25, | an. rh eactaicay- di iledllly integrates directly with the CPU chip or placed on a
separate chipthat has a separate bus interconnect
another. A Process (also So central processing unit) from one proeaie 2skswitg with the CPU. ae :
7 The basic purpose of cache memory is to store program instructions eet
instance of a program) metimes referred to as a task) is an execy tities or thread: frequently re-referenced by software during operation. Fast access to these ms
Q.1.(b) Explain th “oy im, increases the overall speed of the software program.
Ans. Pre-emption © : conc ept of pre ‘ emptio. n. ee (2.5)
Where it is needed ? je | : uli iteria for CPU scheduler : —
Without OE oe ae ea ‘teria to consider when trying to select the “best
ull fica ; relers to the temporary interrupti
or its coop eration, with the intention en a esPensioa n of atask scheduling algorithm for a particular criteriasituation and
(245) Ans : There are sever erent
Te oa steht
2 ae i
Goline auled a conte xt Switch and isa typically performed by:res the:umethat
pre: tasKk] later, Thishe ag oe tizati
* CPU util izat onion - - Ideally the CPUPiwouldcusedbe slico
bustdy100% of trentthe 40%0time, so
Fane (lightly
resume yo eetasksae Tun
thieninOper
g inatin system
theg syst em authorized t sas ie Schedule,, waste 0 CPU cycles. On a real system CPU usag
OE eee ereate and lat loaded) (90 (beasiy ee
N eeded: d per unit time. May range from
4 *
Throughput - Number of eae ae ;
Sea Ma en scheduler preemptible has the advantage of better system res 10 / seco nd nar
to 1/oun
hour the !specific
* Tur depe ndin g on
d time - Time requ ired for a particular process to comp lete, from
atabuty, but comes with the disadvantage of diitions (where th ii
Process accesses the same resource befor
Gnip

th ol race cond : a
i “XCcuting
seatert ti letion. ( Wall
SU bmission time to. completi clockproce
time. ) spend in the readdyy queue waititiing
re anot her preempted process finished using it) e Waiting time - How much h time sses q
eile Aue
(C 1s cuss various types of resources ? ume p
(25)AY their« turn to get on the CPU 2
rage number of processes sitti2 ng in5 the ready queve
Ans . perating system resources are the physical or virtual components
of limitaa o (Load average -The poe Reported in 1-minute, 5-minute, and 15-minute
availability within 4 computer system. Every
device connected to a computer cvetanil waiting their turn to get aes ) nor 2a
< resource. Every internal system component is a resource. Virtual system resouail See ses nae m3?
include files, network connections and memory areas. taken in an interactive program from the issuance of
‘ e Response time -The time se to that command.
CPU time, ; memoryLory (rand
\Tanotdom access memory as well as virtual memory), } mma nd to the commence :
seco ndar y * o of a resp on :
mean by deadlock? Is it possidte ‘ble to have a dead lock in
storage like hard disks, network throughput, battery power, exte
_ resources of a computer which an rnal devices are al]s | Q.1.(g) What do you
; 9 (2.5)
operating system manages. . ing only single process: ing the same
Q.1.(d) Describe the role of TLB | arya suk : a situation in which two computer ae ees “ting in
in address translation.
Ans. A translation lookaside bu (2.5) 3 ffectively preventing each other from accessitisopera ting systems ran only
ffer (TLB) is a memory cache tha
translations of virtual memory to phys t stores recent Se ee i ee to function. The earliest computer
ical addresses for faster retrieval. both program
When a virtual memory addre Ss is refere |
nced by a program, the search starts in
the CPU. First, instruction caches are checked.
If the required memory is not in these
very fast caches, the system has to look u p the memory’s
physical address. At this point,
TLB is checked for a quick reference to the location in physical memory.
When an address is’searched in the TLB and not found, the physical in a system. :
memory must ¢ Mutual Exclusion.
be searched with a memory page crawl operation. As virtual memory
addresses are ° Hold and Wait.
translated, values referenced are added to TLB. When a value can be retr
ieved from
TLB, speed is enhanced because the memory address is stored in the TLB on e No Preemption.
processor. )
Most processors include TLBs to increase the speed of virtual memory operations throu
gh — :
failing a necessary
_ 1] ‘rcular wait with only
a circ le with the first one.
the inherent latency-redu cing proximity as well as the high-running frequenc
ies of current — re +s no second process to for m
Icinnab er es a "The
m™ CPU’. ad lo ck in vo lving only one
n for Ci rc ui t wt de
TLBs also add the support required for multi-user computers to keep memo
nd it
co it j io ssible to have a ‘ ntaining free spaces on disk. (2.5)
ry — d fast
| Separate, by havinga user and a supervisor mode as well as using permissions on read — me 21. ~ Discuss various Gi GORS a rai atio n of fi le s p a c e a n
nd write bits to enable sharing. | Ans. TheThe main idea
= : behind allocation in See
loc on
©
) access of the files. There are three types
,


;
>

:
*
:
-e
:
re

.
14~2017
Sixth Seme
Ie contiguous r, Operating
allocation Systems
linked all
ocation

LP University-(B.Tech.}| -AB Publisher 201 7-15


les: acthe
tual a fj 3 | me
le data on the disk drive, the
here it is on the
e disdj me € of of each file * If Logical Address Space = 128 M words = 2" x 2”° words, then Logical Addres
in use by the file yep , when iti wag la le , Sys log, 277= 27 bits
ing Parts of the disk are “free”. Fre
in métadat e arvas ire
.~ Metadata, and so available for storing new feay ; * If Physical Address = 22 bit, then Physical Address Space = 2” words = 4 M words
tables”, ete.) ata 1s stored are often called “inode (1 M = 22°)
s”, “chunks”, ile act
To
¢ If Physical Address Space = 16 M words = 2* x 229 words, then Physical Address
keep tr
tracks all the disk bl ‘
_ log,2“ = 24 bits
oke WhapePace, the le system maintains a free.
for the file and ths f create a file, the
XS which are free. To SPace lig, The mapping from virtual to physical address is done by the memory management
required unit (MMU) which is a hardware device and this mapping is known as paging technique.
other. we °'responding space is removed from the free ]j Space is ‘g " |
* The Physical Address Space is conceptually divided into a number of fixed-size
St linkeg ton
Q.1.(i) Why is Page size al
blocks, called frames.
ratherAns.
ther,It 'S Most efficient to break
& © always a power of 2? ¢ The Logical address Space is also splitted into fixed-size blocks, called pages.
the address into X page bits
Bisterta: Seen arithmetic on and 3 e Page Size = Frame Size
the address to calculate the page num ber vs : |
resulta ; s Let us consider an example:
it Position represents a power of 2, splitting
© 1n a page size that is a power of 2. an address be Off,
Ween ji ° Physical Address = 12 bits, then Physical Address Space = 4 K words
Q.1| . G) Wha ,
tis Inode Table ? Describe e Logical Address = 13 bits, then Logical Address Space = 8 K words
Ans. An ino de its contents.
is
about a regular file andan entry in inode table, containing informa tion ( the *e Page size = frame size = 1 K words (assumption)
directory. An inode is a da me ta a
style file system such as ext3 or ext4. ta s t r u cture on a trad 2
Inode number also called as in ition Number of frames = Physical Address Space/F rame size - 4k/1k =@= 2
Contents : dex n Umber
— Number of frames = Logical Addréss Space/Page size = 8k/1k =@= 2,
Logical Address Physical Address|
13 bit 3 ye 12 bit
E ; aaa 10 5)

CPU P ists d ft . =
page Number frame number

if want ‘ |

:
us allowing access to the file.
mee
to acce 0
JA file’s inode number can be foun
d using the Is -i command. The Is -j | ——
Prints the i-node number in
the
comman; number
first column of the report. 3 L_>3 (2)0 = Qa 10
4 Y 2 wor
5 A ae
; rking of paging memory manageme
paging with segmentati nt scheme, Compar 6 3
on. 7
t
Ans. Paging is a Memory (6.5) frame numbe Physical Memory
contiguous allocation of ph
mana gement scheme that elim Page Map Table (PMT) in binary
ysical memory. This scheme inates the nee d for or Page table
space of'a process to be non — contig permits the physical address
uous.
¢ L<S‘cal Address or Vi rtual Addr 3 ed by CPU is divided into - VT ncieal
ess (represented in bits): An ad facrons ees cee of bits required to represent the pages in Logi
by the CPU dress generated ° Page num .
¢ Logical Address Space or Virtual Ad { A ddve Page number . Pi ae
dress Space( represented in words or :
a ae
_ The set of all logical addresses genera bytes); :
ne ~ aoe Number of bits required to represent pat
ted bya program .
)
of a page or p
* Physical Address (represented in bits): An addr or page once
s1Z Logical Address Space or word number
ess actually available on memory
unit Physical Address is divided
into
* Physical Address Space (represented in >
words or b ytes): The set of all physical -
~~

addresses corresponding to the logical addresse


(

s
(ae.

Example: | i
*

* If Logical Address = 31 bit, the n Logical Address Space


= 2°! words = 2 G words (l
oe

™ G = 2%) _ offset.
|

\ 7a
e ~are
perichcs the -jyexcelience f~ \
¥ ue ll
So -
Sixt!
16-2017
ixth Sem este
Basis. for ster, Operati ng Systems
C : Paging
omparison Pu bl is he r 2017-17
Segm
ent LP. Univer si ty -( B. Te ch .| -A B
“ots : creases the degree
in e >
at io n an d
Basic
k easing CPU utiliz
. Page is Of fixed }]
| he du le r se es th e de cr
. used. The CPU ac
Fragmentation agi Ock siae A segment ig :
of multiprogramming
;
f sing may lead to ; Ze Variab] gr ee of mu lt ip rogrammung.
0 internal Segmentati ;
ted agains t th e de
p a t i
(2) CPU utilization is plot te
Ry )
Address ragmentation :
on
may le Ny ming increase s, CP U ut il iz at io n al so increases.
external fra (3) | As the degree of mult
iprogram
c:tio.tion, "ty4
|
The user spec} enta
SMg De he r, th ra sh in g sets 1n and ©
idesided by
is diviv dU inadtdr
peCP ess The user
Wig hedertrey of Se cies oe ig increased fu rt
by two ee. cay
address
Page number and of
fic P
itieg , utilization drops sharply. an d to st op th ra sh in g, we must
: segment numb th is po in t, to in cr ea se CPU utilizatio n i
and : i (5) So, at gramming.
ize offset (Segment = livmit), ea se th e de gr ee of mu lt ip ro |
th, decr of the minimum
The hard le decides the The segment g is caused by un de r al lo ca ti on
Tabi pgs "Ta th e pr ob le m: Th ra sh in
nt in uo us ly pa ge fa ul t. Th e system
by a process, forcing it to co
Eliminat e
“128 ig Specif: |) level
user,
by the ta s; numberof pages required aluating the level of CPU utilizationas compared to the
ee volves a page table Serm en can detect thrashing by ev l of mu lt ip ro gramming.
Pth agi Ng in
ntation involyooN re du ci ng th e le ve
:
at contains base addr thy of multiprogramming. It can be eliminated by 4,2,1,5,6,2,1, 2,
ee segment table that Ba llowing page re fe re nc e st ri ng 1, 2, 3,
of each page. and aa Q.3.(a) Consider the fo d oc cu r fo r fo ll ow in g replacement
le number 2, 1, 2, 3, 6. Ho w ma ny page faults woul (5)
Offsg, 3,7, 6, 3,
; segment length). es):
algorithm (Assume three fram
me |
(b) Given
Q.2.
- memory partitions of 100 K | F
(i) FIFO
Where will the ’ 500 K and 60
0K (in ge
processes 212K
e algorith
ithm, namely,best fit, fi
9 417K , 112K and 426K(ini order) in the memory? whe the (iii) Optimal th ea ch pa ge the time
algorithm makes the most efficient use of memory? | ich on,Ne FI FO : A F I F O re pl ac em e nt a l g o rithm asso sica te s wi
be re pl ac ed , the oldest
Ans. (i ) . When a page ™ us t
br ou gh t in to me mo ry
‘) when that page was
: 2k -> 500K (288 left)’ _ page in chosen.
ee -> We (183 left) Reference string e 6. 3. 22 0 258
3 ets e
x etn
->NoS
fa
426k 5 No Space 9\\2)\2 AL 4\ 2
| IG
|
SLe ni U3
s\tal Valls H
212k -> 500K (288 left) No. of pa ge Fa ul t in FI FO = 16
of th e ne ar fu tu re , thenwe
e re ce nt pa st as an approximation of ti me . Th is approach
417k - (ii) LRU: If we us e th
en us ed for the long es t pe ri od
th at ha s no t be
112k
ee will replace the page cea
pas eee is the Least Recently used
.
tt
a g 2
426k -> No Space Be, {2
Worst-fit: Bi tl iG lall— aia) c 3
a
Ly L4) Lae 3\(3\\3
212k -> 600k ‘\f1) Foltz) e\z\tsilse oO
\ 2\} (2\\8)
ft)c
417k -> 500k (83 lee !E
raUL |
5 Cobb aeehes ES AE
in LR U= 15 aa;
112k -> No Space No. of page fault . pe n s t - ofig time.
page that has not been used
426k Re-> N o Space (iii) Optimal: Replace the
7 us es me mo ry mo st efficient] ot ieee eee
ae es eu shoe Fit algorithms te + x |
y. | ee ; os = Fae 3
is thec a nto ca n th e sy st em do to el im ininate
at sh in g? Wh at 2\\2
th paro“ieblent? use of thra NE ‘ —
a at
a
3 tel ; e\fs} 12]
Ans. Meani
ai 7
" ES iC = i|
4 tinoptimal=11
IfeRthe e Ee| edecnnot uahaeve numb| er of fr "
frames it needs to support
in active fa ul t? Wh at s a e — wo
j Ne ee ad mean by a pase a bl oc k of memory that
use, it will quick ti vi ty is ca ll ed th ra sh in g = « a.
st em wh en 4 pa ge fa ult a ts to acc ess
aeeult notifies the operating
poe nD aare ac w lev el, it sf op er at in g sy ,
In other oe ra ti o de cr ea se s be lo en a pr o Lape
say that when page fault
3
fa ul t oc cu rs wh st or age
? Ans: A page it fr om th e
called thrashing. _
e s 5 ry then tr an sf er
th e ph ys ical me
Causes of Thrashing is not st or ed In memory, thes
}
mu
system that it anst lo ca te th e da ta in
DD or S S to
D th
, e sy st em RA N.
Ae a severe performance problems
i | S| &
device, such
as
Pmeins t

tilization
«

by oie ucla g oe 1s too low then we increase the degree of multiprogramming


process to the system. A global page celaearestll sigurithal is
4s

«a :
ee

18-2017 Sixth Semeste r, Operating Systems


Though the term “page fault” soun ds like an error,
part of the normal way computers ha ndle page faults are common an
virtual memory. In progr amming te Vang LP. University-[B.Tech. LA
page fault generates an exception, w hich B Publisher 2017-19
notifies the operating system that
retrieve the memory blocks or “pages ” from virtual me en 5
mory in order for the Progra Ans: (i) Network and
Distributed
, tt pase, but the difference li Operating Systems have a common hardware
continue. Once the data is moved into es in software.
This process takes place in the back physical memory, the program continues ag ;,, Nt | S.No. Network Operating
ground and usually goes unnoticed by the ui System Distributed Operatin
Most page faults are hand Ser — g System
led wi thout any problems. However, an invalid Page f,
——

ma3 y cause a program to han g 1 A network operating


or crash. This type of page fault may occur when system is A distributed Operating system is
a Progra! made up of software
tries to access a memory address that doe and associated an ordinary centralized operating
s not exist. Some programs can handjq protocols that allow a se
types of errors by finding a new memory ad thaw t of system but runs on multiple
dress or relocating the data. However ifae ee computer network to be
program. cannot handle the invalid page fault, it will get used together. independent CPUs.
which may terminate the process. This can cau passed to the Operating syste, 2 Environment USeTS are aware
of Environment users are not awar
se the program to unexpectedly quit © multiplicity of machines. e of
While page faults are common when working with virtual memory multiplicity of machines
, each paga ¢, 3 Control over file placement is
requires transferring data from secondar Be fay), | done It can be done automatically by the
y memory to primary memory. This manually by the user.
several thousand time PTOCeg,
may only take a few milliseconds, but that can still be System itself.
4 Performance is badly affected if
than accessing data directly from memory. Ther Ss Slowe, It is more reliable or fault tolerant
efore, installing more system Memo certain part of the hardware starts |
can increase your computer’s performance, since it will need to 1.e distributed operating system
access virtua] malfunctioning.
less often. |
Memory performs even if certain part of the
hardware starts malfunctioning.
Steps taken by operating system to handle a page fault 5 Remote resources are accessed by
| Users access remote resources
Here is the sequence of steps which occurs in handling a page either logging into the desired in
fault; the same manner as they access
(1) Hardware trans to kernel mode. remote machine or transferring local resources.
data from the remote machine to
(2) Program counter is saved in stack. | user’s Own machines.
(3) Current instruction state is saved in CPU registers.
(4) An assembly code program is run to save general registers and o ther inf (ii) Following are the differences between multiprocessing and
ormation — multiprogramming.
(5S) Operating system founds that page fault has occurred. ,
Ans.
(6) It finds a virtual address which caused the page fault by using a hardware
register or by using the software. S.No. Multiprocessing Multiprogramming |
(7) Virtual address is checked to see if it valid. If it is not valid then proce 1 Multiprocessing refers to processing |
ss a Multiprogramming keeps several
~ killed. ; of multiple processes at same time programs in main memory at the
(8) It is also checked to see if a protection fault has occurred. by multiple CPUs. same time and execute them
(9) If virtual address is valid and if protection fault has not occ concurrently utilizing single CPU.
urred, then, operating —
tem checks if a frame is free. , 2 It utilizes multiple CPUs. It utilizes single CPU. \
(10) If there is no frame free, then page replacement 8 It permits parallel processing. Context switching takes place. \
algorithm is run.
(11) If selected page frame is dirty, page is sc 4 Less time taken to process the jobs. More Time taken to process the Jobs.
heduled for transfer to disk.
(12) Context switch happens and the process 5 It facilitates much efficient utilization Less efficient than multiprocessing.
and another process is run. which caused the fault is suspended
| of devices of the computer system. |
SNe ae ae
(13) Frame is marked as busy. 6 Usually more expensive. Such systems are less expensive.
(14) When page frame is clean, then the
page is loaded from the disk. UNIT-I1
(15) When the page has been loaded ,
page frame is set in normal state. set of pro ces ses , with the length of the sin
(16) Instruction that c aused the fau ) Q.4 . (a) Con sid er the fol low ing
lt is set to initial state program counte
to point th is instruction. r is reset burst time give in milliseconds:
(17) Process which caused the fault is Priority
scheduled. Process Burst Time
(18) Operating syste m runs assembly langua
other state information.
ge program to reload registers and Pl . ;
P2
(19) Control is shifted back to us
er space for execution. P3 : :
Q.3. (c) Differentiate the followin
g: - rePp4 fy 4
(i) Networked and Distributed (4)
operating system.
(ii) Multi programming and Mult
i-Processing operating system. -
a Tr
e
20-2017 Sixth Semester, Operating Systems
waiting time of each
process for the following scheduling algorj
(ii) Priority (Non- foe
nh preemptive) (ili) RR (quantum of 2m)
Jw
thmes ,
@s, OR, I.P. University-[B.Tech
LAB
. Publisher
ee 2017-21

13+1+15+5+20 |
Average TAT = : = * = 10.80 milliseconds
Process Burst Time Priority |
Average WT =a 9+0+13+1 34 pa
5 4+15 = . 6.80 milliseconds
P2 { 1 (iii) RR (quantum of 2 ms):
Ps 9 3

P4 Ae 2 Gantt chart: |"" | * Fo | PA) Ps ft pt P4 | PS | P4 | PS | Pt


0 > 3 5 7 9 "1 > 616 AE = 4a- 20
P5 5 4
Arrival ; Burst Tum Around e
Process Time (AT) Time (BT) Completion Time (CT) — AT) rare eT se

TAT = CT - AT
(i) FCFS: WT=TAT — aT st .: | 8 20 20 12
P2 0 4 3 3 2

P3 0 B. 5 5 4
| 5
Grantt Chart: fe Pea pees P4 0 4 13 13 9
0 8 g 1.. 16-20
. : | Wan P5 0 5 18 18 13
Process | Arrival Time} Burst Time|Completion Time Tur one THe

0 8 8 8 0 20+3+5+134+18 59
P1
8 Average TAT = 5 ar 11.80 milliseconds
0 1 9g g
P2
P3 0 2 yan 11 AOE 12+2+3+9+13 39 at
0 4 15 15 14 Average WT = 5 7 7.80 milliseconds
P4
P5 0 5 20. 20 15 Q.4. (b) Describe Process State Diagram. (3)
Ans. To start off with the details, a program when needs to be executed goes through
entire operation until
o deck 8+9+11+15+20 63 a process. This process has several state changes in the
= 5 = ; prog ram. Upon succ essf ul term inat ion, the program would get useful
Average Turn Around Time term inat ion of the
user. This entir e proc ess prog ress ion goes thro ugh state changes which
results to the
= 12.60 milliseconds. |
are mention below in steps:
| 0+8+9+114+15 43 | 1.The process enters a state called NEW STAT
E.
Average Waiting 'Time = = 3
RE AD Y ST AT E.
5 5 2. The process then enters the
to an AC TI VE ST A TE /R UN NI NG STATE (Execution of
= 8.60 milliseconds. 3.The process then goes
(ii) Priority (N on-Preemptive): Lowest number yet higher priority. the program starts here).

Gantt Chart: pears Bt 2 fi


0 1 5 13. 15 20

3 Z | Turn Around | ; |
Process Arrival
(AT)Time Burst
Time(BT) ;
Completion Time (CT) ae Ps Waiting time
WT = TAT- “ (Ws) 7
+ —
P14 Or: 8 13 13 5
P2 : 0 1 1 1
f , scheduler dispatch 1/0 or event wait
P3 0 2 15 15 13
P4 0 4 Be 5 1 /O or event completion

PS 0 5 20 20 15 t h E n t i r e 0 e ration
s t a t e D i a g r am wi e
Fi g . P r o c e s S
22-2017 Sixth Semester, Operating Systems
4.The process ends with the HALT STATE/T
ERMINA LED STATE (afte
program BURST’s are over. The program might be terminated for
terminated normally), cibly op ly LP. University-(B Tech.
LAB Publisher 2017-23
&i repeat
Q.4. (c) What is the role of Medium Term Scheduler?
flagii] := TRUE;
Ans. The use of medium term scheduler is to improve multiprogramm;
multiple processes to reside in main memory by swapping : Dgby ay turn :=j;
eA out procegsseg th at reset
(need I/O) or low priority processes and swap @ while (flag{j] and
ping in other processes that Were ity turn =}) do no-op;
queue. So you can see that we requied medi dium um term scheduler when Nyij CRITICAL SECTION
memory. This swappin g in and out operation does We haya
not take place when We are ty flag{i] := FALSE;
a single small program and have large memory.
: REMAINDER SECTION
Similary if we are running multiple programs and we have very. large Memon,
until FALSE;
than the size of all processes plus addition space for other requirements) then ru
term scheduler is not needed. Modern Information common to both
operating systems
USE Paging go ; edi processes:
Swapping processes they swap pages in and out of memory.It is same as insteas®
a System vi
turn = 0
very large memory(infinite) would not suffer from page faults. | flagi0] = FALSE
Q.5. (a) What do you mean by Critical Section? What are various met flagi1] = FALSE
handle critical section problem? Write a solution for Dining /Phjj hods tb
EXAMPLE 1
problem using Semaphores. , | | S0| DhQj
e

Ans. Critical Section : | mel Process 0


Process 1
=
A Critical Section is a code segment that accesses shared variab i=0;j=1
executed as an atomic action. It means that in a group of cooperati les and has toy, i=1,j=0
flag{0] := TRUE
given point of time, only one process must be executing its critical se ae Processes at.
ction, If any oth e turn := 1
process also wants to execute its critical section, it must wait until th e€ first one finishes check (flag{1] = TRUE and
Solutions to the Critical Section Problem
turn = 1) |
Assumption - Condition is false because
* assume that a variable (memn ty location) can on flagi1])= FALSE-
ly have one value; never “betwee |
values” - Since condition is false, no
* if processes A and B write a value to the same m em waiting in while loop
ory location at the « ;
time,” either the value from A or the value from B will : - Enter the critical section —
be written rather than Some
scrambling of bits - Process 0 happens to lose
Peterson’s Algorithm | the processor
* asimple algorithm that can be run by. two pro flag{1] := TRUE
cesses to ensure mutual excl
for one resource (say one variable or
data structure) usig, turn :=0
* does not require any special hardware check (flag{0] = TRUE and turn = 0)
* it uses busy waiting (a spin - Since condition is true, it keeps busy waiting
lock)
Peterson’s Algorithm until it loses the processor
- Process 0 resumes and continues
until it finishes in the eritical
section
- Leave critical section flag{0] :
var flag: array [0..1] of = FALSE
boolean; - Start executing the remainder
turn: 0..1;
(anything else a process does :
%flaglk] means that proces besides using the critical section)
flag[0] := FALSE; - Process 0 happens to lose the
| processor
flag[1] := FALSE; check (flagi0] = TRUE and turn = 0)
turn := random(0.,1) _ This condition fails because flag{0] = FALSE
After initialization, each proces j - No more busy waiting
s, which is called »rocess i in th de (the other - Enter the critical section
Process 1s process /), runs the following code: —% ue de | ae

a
ee »
La —
ems
24-2017 Sixth Semester, Operating Syst

EXAMPLE 2 LP. University-[B.Tech.]-AB Publisher


Process 1 2017-25
Process 0
STEP K

bald
i=1, j=0
120, j=l
flag{[0] = TRUE
turn = 1
- Lose processor here
flag{ 1) := TRUE
Philosopher
turn :=0 |
check (flagl0]= TRUE and turn = 0)
Condition is true so Process 1

check (flag{1] = TRUE and turn = 1)


busy waits until it loses theprocessor
ee
- This condition is false because
turn = 0
- No waiting in loop
- Enters critical section
4
O noodles

EXAMPLE 3)
PA ,

ae .

Process 0 ‘6 Process 1
chopstick
i=0, j=1 i=1, j=0 iar

- Lose processor here Semaphore Solution to Dining Philosopher -


flagi1] = TRUE turn = 0 ae Each philosopher is represented by the following pseudocode:
check (flag(0] = TRUE and turn=0)
process P\i]
- Condition is true so, Process 1 |
busy waits until it loses the processor _ while true do
turn:=1 check (flag [1] = TRUE a al { THINK;
and turn = 1 PICKUP(CHOPSTICK{il, CHOPSTICK[i+1 mod 5));
- Condition is true so process 0 busy EAT; |
waits until it loses the processor PUTDOWN(CHOPSTICKIi), CHOPSTICK[i+1 mod 5})
check (flag{0] = TRUE and turn = 0) }
- The conditions false so, Process 1 enters the | There are three states of philosopher : THINKING, HUNGRY and EATING. Here
critical section : there are two semaphores : Mutex and a semaphore array for the philosophers. Mutex is
time.
| Swap used such that no two philosophers may access the pickup or putdown at the same
semaphores can
* another type of hardware assistance for process syn The array is used to control the behavior of each philosopher. But,
chronization
* a special hardware instruction that does a compl te Mama rily three ; result in deadlock due to programming errors.
operations) atomically : plete swap (ordina
Code -
* 1.e., the complete swap is executed or no
part of it is #include <pthread.h>
* given pass-by-reference parameters A
an: d B, it swaps they values
Swap Solution to the Critical Se #include <semaphore.h>
ction Problem :
* uses two variables called lock #include <stdio.h>
and key
* intuition: if lock is false, th
€n a process can enter the critica] section, and oth
erwise it can’t )
* initially, lock is false #define N 5
repeat : #define THINKING 2
|
var = true 7 #define HUNGRY 1
while (var == true) sw ap(lock, var): #define EATING 0
critical section
: a
#define LEFT (phnum + 4) %oN
lock = false; + 1) % N
#define RIGHT (phnum
remainder section
until false }
4
26-2017 Sixth Semester, Operating Systems

int state[N];
int phil{N] = { 0, 1, 2,3, 4}; LP. Univers;
‘F. University
Tech
-( . B.
|-AB Publisher 2017-27 Ow
test(LEFT); |
sem t t . test(RIGHT),;
iar gare
sem_post( &mutex):
a 49
}
tne test(int panum)
void* philospher(void* num)
| { se
if (state[phnum] == HUNGRY | while (1) {
&& state[ LEFT] != BATING : int* i= num:
&& state[RIGHT] != EATING) | | | sleep(1);
// state that eating
state[phnum] = EATING;
take_fork(*i);
sleep(0);
put_fork(*i);
sleep(2);
| }
printf(“Philosopher %d takes fork %d and %d\n", poene +4, ss +1, Phnun, : ah
printf(“Philosopher %d is Eating\n”, phnum + 1); | om aS
Became Sete has no effec pthread t thread id[NI;
Bring Vake1or | // initialize the semaphores
ee to is hungry philosophers _ . | - + gem_init(&mutex, 0, 1);
uring putior
for (i = 0;1< N; i++)
sem_post(&S[phnum]); | . — sem_init(&S[il, 0, 0);
} | NR . : | for (i = 0;i1< N;1++) |
| 2 , | // create philosopher processes on
Bogen ices | , | NULL,, philospher, &philli);
pthread_create(&thread_id{i]
SOE ERE MOISE SU) | | "2 printf(“Philosopher %d is thinking\n",i+ 1);
( oe 7 |
sem_wait(&mutex); , i. for (i = 0;i< N;i++)
// state that hungry : | ? a pthread_join(thread_id{i], NULL);
state[phnum] = HUNGRY; | ‘a. | Me (4)
printf(“Philosopher %od is Hungry\n”, phnum + 1); | “< Q.5. (b) Discuss Dekker’s Algorithm. ger eda
// eat if neighbours are not eating test(phnum); | | aL. Ans. Dekker’s algorithm was = ae - a 2 and an integer variable:
sem_post(&mutex);
problem. vaIt requires both an array
//if unable to eat wait to be signalled r flag: array (0..1) of boolean;
sem_wait(&S[phnum)); Raev ks turn: 0..1;
rig yee e en repeat
| ae | | flagli) := true;
// put down chopsticks
void put_fork(int phnum) ‘t | while flagti] do
if on
sem_wait/( &mutex): : ae a flag{il := false;
//state that thinking while turn = j do no-op;
state[phnum] = THIN flag[i} := true;
KING;
printf(“Philosopher %d putting fork %d and %d a end; i
print
;
f(“Ph

iloso
;
pher %d is thinking\n”, phnudown \n”,
m + 1): Se
hn L ¥ i os :
+) LEFT +1, “3
4 | arr cas
, 3 i urn = Jj;

_"
26-2017 Sixth Semester, Operating Systems
: e
int state[N)]; *

int phil[N] = { 0; 1,2;3,4 iF | | siontttt LP. University-(B Tech. |_AB Publisher 2017-27

sem_t mutex:
eadpetr
sem_t S[N];
; oid test(int phnum) ee
void* philospher(void* num)
if (state[phnum] == HUNGRY
| 7 " while (1){
&& state[LEFT!=
] EATING _ int* i=num:
&& state[RIGHT] != EATING) { | ig sleep(1); :
// state that eating take_fork(*):
| state[phnum] = EATING; sleep(0);
put_fork(*i);
sleep( 2); | ; }
| J
printf(“Philosopher %d takes fork vA and %d\n’”, pheam +1, ae +1, Phnum , | |
printf(“Philosopher %d is Eating\n”, phnum +1); I, int main()
3 4 . (

//sem post(&S{phnum]) has no effect. a | inti;


// Sais es . pthread t thread_id[N];
// used to wake up hungry philosophers | te | | // initialize the semaphores
// during putfork a3 Saitee f ' gem_init(&mutex, 0, 1);
sem_post(&S[phnum]); | | ane for G =0; i — re?)
, sem_init(&S{il, 0, 0);
: | i : y . for (i = 0;i< N; i++) {
k hoostick | e ae | E // create philosopher processes
{dake up Coens AUG | a NULL, philospher, &philli));
pthread_create(&thread_idli],
os ake
or kGny panes) | 3 ‘g printf(“Philosopher %d is thinking\n", i + 1);
;
, }
:
:
,

sem_wait(&mutex); | | . oa | | | fon GOs Nee)


>

// state that hungry pthread_join(thread_id{i], NULL);


state[phnum] = HUNGRY: | —_— |
printf(“Philosopher %d is Hungry\n”, phnum + 1); | | Q.5. (b) Discuss Dekker’s Algorithm. cu (4)
// eat if neighbours are not eating test(phnum); Ans. Dekker’s algorithm was the first provably-correct solution to the critical section
sem_post(&mutex); | problem. It requires both an array of boolean values and an integer variable:
//if unable to eat wait to be signalled var flag: array (0..1) of boolean;
sem_wait(&S[phnum)); ea Ne a turn: 0:2h5:
poe haere iS an repeat
. Bes . | a | flag{i] := true;
// put down chopsticks et | while flag|j) do
me put_fork(int phnum) | 5 if turn =j then
| Ne | Beer Mh ' begin
sem_wait(&mutex): | iat ae | —_ | flag(i] := false;
//state that thinking while turn =] do no-op;
S tate[phnum] = THINKING;
flagli] := true;
printf(“Philosopher %d put; fork %d and %d down \n” ae : < end;d; "
fae putting
printf(“Philosopher %d is thinking\n”, phnum + 1): — +1, LEFT +1, phmumie My . ) critical section
oe turn :=J;
-
.€ XPEPicl J% —

t
26-2017 Sixth Semester, Operating si cp:
int statelN):
int state[N]; LP. Universit -(B.T
int phil[N] = { 0, 1, 2, 3, 4); Y-\B.Tech.|-AB Publisher 2017-27
test(LEFT);
_ test(RIGHT);
sem_t mutex;
sem_post(&mutex);
sem_t S[N];
void test(int phnum) est
void* philospher(void* num)
| | { .
if (state[phnum] == HUNGRY ; ae {
&& state[LEFT] != EATING
* 1=num;
&& state[RIGHT] != EATING) | | oS ‘aie
// state that eating | 3 |
|
| | 7 salt (*1);
_ State[phnum] == EA EATING;
put_fork(*i):
| | \
sleep(2);
|

printit’Philosopher %d takes fork ‘od and'0a\F P2BREL Eris Phnum ,, I


printf(“Philosopher %d is Eating\n”, phnum + 1), eae iint main()
| | atte
// sem_post(&S[phnum]) has no effect + | 4 int 1;
| r pthread_t thread_id(NI;
// during takefork ; | | // initialize the semaphores
Hiaued to wake
// during putfork
up bunety DA ee ent | _-» - gem_init(&mutex, 0, 1);
| for (i =0:1 <N: 144)
sem_post(&S[phnum)]); | an sem_init(&S[il], 0, 0);
| . | x for G =0;1< N; i++) {
: | | // create philosopher processes : spi
// take up chopsticks Stiyf : | ne pthread_create(&thread_id{i], NULL, philospher, &phnil{i));
void take_fork(int phnum) | | ta printf(“Philosopher %d is thinking\n", i+ 1);
{ , : |
sem_wait(&mutex);
for (i= 0;i<N;i++)
// state that hungry
er 4 pthread_join(thread_id{i], NULL);
state[phnum] = HUNGRY;
| ~.
printf(“Philosopher %d is Hungry \n’”, phnum + 1); © ; e (4)
Q.5. (b) Discuss Dekker’s Algorithm.
// eat if neighbours are not eating test( phnum); rec t sol uti on to the critical section
| | oy . Ans. Dekker’s algori thm was the firs t pro vab ly- cor
sem_post(&mutex); | i iable:
variabl e
eA Sal nf roblem. It requires both an array of boolean values and an integer
//if unable to eat wait to be signalled ah P var flag: array (0..1] of boolean;
sem_wait(&S[phnum)): RE ex | turn: 0..1; -
sleep(1);
ia repeat .
} | ial E flag{i] := true;
// put down chopsticks ae f while gees 8
void put_fork(int phnum) ay if turn =} then

sem_wait(&mutex); ae begin
//state that thinking
- flagtil a sit
E while turn = ) © No-OP;
state[phnum] = THINKING;
y flag{i] <= true;
Pantit"Philosopher %d putting fork %d and Yd do a a
printf(“Phil
“DL; osopher %d js thinki
| ng\n”,
end; )
i phnum wn+ \n”,
1): phnum ! + L: LEFT + +1, ho » Lae ) critica
ae l section
.

turn :=j}
28-2017 g:
ixth Semester, Operating Systems
flagli] := false;
remainder section
until false;

UNIT-III ‘
Q.6.(a) Consi Onsider the following snapshot of a system. All resources are remqueste
Sted at once
« In some cases pree
: n
Process: All ocatio Max Available Avoidance: Pts More than often necegs
A B a A a C iz 5 « The cal for deadlock avoid , =
0 | é * Deadlock avoidance ig of ance is to th
PO
1 0 1] 5 3 3 3 ae ° The system requires ade “1 Impossibl
P] use of each resource for each oe apriori inf
0 2 0 0 3 9 2
0 9 e In order for the syatita tei
3 0 3 9
2 2 or unsafe, it must know in Scae, a
9 1 1 9
PS
available, anncdre chnia«any time the numbe T and type of all resources in
existence,adlo
P4 | | OR a2 4 3 3 e De ck avoida te
0 A es include B ;
it ete
: : g ‘hig e Resource allocati © Sanker’s algorithm, Wait/Die Wound/
A ad the foll ow in g questions usin Banker’s algorithm. ; on str
;
:
the . (By that of detection and pdeecikion gy for deadlock avoidance selects midw ay between
Gi) s8 System in a safe state? |
* Needs to be manipulated until at]
oa - east from process P1 arrives for (3,3,0) can the request be atleast one safe path is found
iately? Granta, « ‘There istic piéewniiion
| Q.6. (c) How can the no-preempti
|
Ans,
d? em pt io n an d ci rc ul ar wait conditions b
prevente 3)
Pro cess ae Max Available Nessa . Ans. No Preemption
>
Preemption of process resource allocations can pre
:
7
A B C ABC ABC
/ | _ le.
when it is possibp Prevent this condition of deadlocks,
PO 010 753 322 | o One ap ris if a process i
thact h
oa :
| 743 new resource,
a ng
P : 129 then all ot he r re so ur ce s iv ed ia ua ty fa a Ah a ae
s
Fequesti
are imp lic itly released,
322 ed ), fo rc in g thi s pr oc es s to re- ac oe es pr oc es
| : 200 | (preempt
P2 302 902
P3 211 99:9 | 600 -_—‘ resources in a single request, similar tothe widest Ss aan eS
o An ot he r ap pr oa ch i eces
A ‘OLs
rs sis guatens aes — = nis in a re so ur is requested. and not available, then
P4 002 433 |
cee er processes currently have those resources and are
themselves blocked waiting for some other resource. If such a process is found, then
(i) The content of the matrix need is d efined to be MAX — Allocation
i ai
and isaboy, .. some of their resources may get preempted and added to the list of resources for which
We claim that the system is currently
) i in safe state. the process is waiting.
P4, P2, PO> satisfies the safety criteria. i ? ate: ndced, Use sedate <P1, P3 Fither of th states are
: o Either of these approaches may be applicable for resources whose
Gi) You should:he ablettace
in this statendt easily saved and restored, such as registers and memory, but are generally not applicable
request fon'(6 310) betPe cian me however, that, when the system is not availa i to other devices such as printers and tape drives.
ecnicel 2 aig ire Se i ae since the resources are ;
cs — ie oe
granted, even though the resources are available is to number all resources, an to require that
since the resulting state is unsafe. e One way to avoid circular wait
our ce s onl y in str ict ly inc rea sin g ( or dec rea sin g ) order.
(b) What isi the di: fference between deadlock avoidance and prevention? processes request res
Q.6. b
s, in or der to request resource Rj, a process must first release all Ri
4 e In other wo rd
Ans: SE ili such that1 >= 7 oe
(3)
| 2 a foe
s sc he me 1s de te rm in in g the re al y ordering of the
¢ The HS laomcse 7
- . ce in thi
0 of th e ne ce ss ar y co nd it io ns for deadiaal
1s to ensure that at least one 0 to 199. The
never Renae drive ha s 20 0 tr ac ks nu mb er ed
Q.7. (a) Suppose that a disk mb er 100 . Th e re qu es te d tracks,.
eadlock prevention is often impossible u est at track nu
'18,90,16 0,38,184. What is
- :
1 a
.

drive is currently serving a req


D .
.
&
.
to implement :
i | fori; information | || . ed by by the the disk scheduler are 55,58, to satisfy ©all the pending
3in order received en
_* The system doesn
sone t requ ire addit lonal apriori i trac ks) that disk arm move s t o sauity
potential use of each regarding the oval s | the total distance (in
© ondor foc resource for each process, for each of the foll owin g disk sche duli ng algorithms:
condition it do requests,
to pr even t the dead lock
all the details of al] Behe
sources In existence, available and request a. —
e ae h pp
(ii) SSTF
ee* Deadlock preventio n techni
ques incl | i— (iii) SCAN
serializing tokens, Dijkstras. algorithm rays non-blocking synchronization algorithms,
al (iv) C-SCAN
30-2017 Sales
Sixth Semester, Operating Systems
(v) LOOK
Ans: (i) ECFs:
LP Universit
\ S MH
0 18 38 39 55 58 Total distance in C.g¢AN:
Y-(B.Tech.|
-Ap
Publisher
:
2017-31 —
90 100 160 184 gg
b Strvas bc

( 160 — 10da0) + (184 = 160) + (199 _ 184) + (1


99 — 0) + (1g—
_
. 100
55
(v) LOOK: ~ 98) = 388 cylinders

39 58
18

90

ee
, et alas 184 Total distance in LOOK
The total distance in (160 — 100) + (184 - 160) + (184
FCFS: _ 90) + (90 ~ 58) + (58 —55) +
(100 — 55) + (58 — 55) + (58 — 39) + (39 — 18) + (90 — 18) + (55 — 39) + (39 — 38) + (38 — 1g) - 25
0 cylinders
(160 — 90) + (160 ~ 38) + (184 — 38) = 498 cylinders. Ti Q.7.(b) What are various parameters
for evaluating Disk performance?
(ii) SSTF; scuss. :
Ans. Higher performance in hard disk (4)
drives comes from devices which have better
0 18 38 39 55 58 90 100 performance characteristics. These devices include those with rotating media,
160 184 199 hereby
} i 4 7 Fazwosd | T 1 called rotating drives, i.e., hard disk drives (HDD), floppy disk
| drives (FDD), optical
100 discs (DVD-RW / CD-RW), and it also cover s devices without moving parts like solid-
state drives(SSD). For SSDs, most of the attributes related to the movement
of mechanical components are not applicable, but the device is actually affected by
some other electrically based element that still causes a measurable delay when isolating
and measuring that attribute.These performance characteristics can be grouped into
- two categories: access time and data transfer time (or rate).
The total distance in SSTF: Access Time:
The access time or response time of a rotating drive is a measure of the time it takes
(100 — 90) + (90 — 58) + (58 — 55) + (55 — 39) + (39 — 38)
before the drive can actually transfer data. The factors that control this ee om .
_ + (38 — 18) + (160 — 18) + (184 — 160) = 248 cylinders rotating drive are mostly related to the mechanical nature of - rere ape ss
moving heads. It is composed of a few independently measurable eleme
nce of a storage
0 18 38 39 55
added together to get a single value when evaluating the performa
+ | bie 58 90 100 160 184 199
= 1 T T T
| device.
T T + + er to obtain the access time
The key components that are typically added togeth
} }—
. 100
uge 184 are:
199 | e Seek time
—<—
e Rotational latency |
39 55 :3 (8 2 ~ e Command processing time
38
eer

18 e Settle time
Total distance in SCAN:
internal
(160 ~ 100) + (184 — 160) + (199. Transfer Rate:
covers ee Se
oe

t a t
-The = dgta.trg as nate of a drive (also called throug hput)
< disk surface an d the con t system).
eo

on the drive and the host sy


the controller
a

ee pe
ee SEP

bee al
extern mee
rate
da ta tr an sf er ra te wi ll be the
- The measurable
1s
sited

1” al la te nc y
e i si 98 90 100 160 184 199 Q.7.(c) W h y ro ta ti on
! | |
position informa
to
th re
e host.

160
. tion

al
a,
| ' |
xp their rotati
;

184
ee

100Po pl84 scheduler would be subjec


Ans. Most disks do 20° & is)
ee a eeibe
is var :
iab le, so the r ota tional
6_\'s

0 | pees porier scheduler


Sei ey did, the Sa nsum
.

Ev en if th
EPO

18
38 39 65 5 %
imprecision and the time C0
et
eae
:
;

ftrns
7:
32-2017 Sixth Semester, Operating Systems
Position information woul
d become incorrect. Furthe
given in terms of logical bl r, the disk "equegt,
ock numbers, and the mapp
Physical locations is very ing between logica) arbi, ly, |
complex.
4
L.P. University-[B Tech.
|_AB Publisher
t Advantages:
UNIT-IV | Both the Sequential and Dire
Q.8. (a) Describe various file > the address of the kth, block ct Accesses are supported by th
is. For direct access
allocation methods. Compare ich starts at block b can easily of the file wh
index allocation with contiguo an d, be obtained a
us file allocation scheme, (b + k)-
| | “ony, This 1s extremely fast since the nu
Ans, File Allocation Met mber of seeks are minimal because
hods | contiguous allocation of file bl of
7 stored in the di Disadvantages:
ocks.
thr ane allocation methods def ine how as sitie os Z = Plocks, Ther, |
wee Main disk space or file allocatio ¢ This method suffers from both int
n me ernal and external fragmentation. This
—* Contiguous Allocation a ¢ inefficient in terms of memory utiliz makes
ation.
* Linked Allocation ‘am? ‘© Increasing file size is difficult because
it depends on the availability of contiguous
* Indexed Allocation |
memory at a particular instance.
Thehiemain idea7 behind these methods is to provide: ) 2. Linked Riek Siceaston ‘Soe
sstheasie ) | — In this scheme, each file is a linked list Te,
of disk blocks which need not be contig) uous.
“Micient disk space utilization. . a " The disk blocks can be sca
ttered anywhere on the disk.
| | . The directory entry contains a | bee aes
* fast access to the file blocks. pointer to the starting and the ending
All the three methods have their own Each block contains a pointer to the file
next block occupied by the file.
.

advantages and disadvantages 88 dis s

a The file jeep’ in fol


e,.
;

lowing image shows how the blocks are randomly ee c .

ae ee
; Th

1. Contiguous Allocation * t block (25) contains -1 indicating a null pointer and does not point fo any o
| : las
In this scheme, each file occupies a cont pt
: iguous set of blocks on the disk. directory .
if a file requires n blocks and
assigned to the file will be: 6, b+ the hl... file start end
, 6+2,....6+n-1. This means th |
block address and the length of the file (in te at given the startin, ieep 3 25
rms of bloc ks required), we can determin 1 4] of] 3
the blocks occupied by the file. 0 1 3
: | +
* Address of starting block
* Length of the allocated portion.
The file ‘mail’.in the following fi | es |
gure starts from the block 19
: : 7 Therefore, it occupies 19, 20,
21,22, 28, 24 blocks. with length =6 blocks 12113 “F SL
18[_\17(_}181_J19
i ee ae i ) 20(_J21 EF J22 23}
count | file, Start le length i ae
OL 12) 2L) 3 oal_j25t 126127
count 0 2
4 5 6
f ;
7 [es i 14 3
30|. 131
mail 19 6
S 29 ,
8 9L_}10{_ /414
: list 28 4
tr am f 6 2 ) ; d easily since
ia 3 Advantages: spe t be in cr ease |
21131140) 15 0 f fil e si ze . Fi le si ze ca n
e This is very pee .
in terms 0
for a contiguous = rf a memory.
18/17 }1sCjige ee t This makes it relatively
tem does not heve fragmen
yy _mail Oo S
20L-J21_J22[ Jos a me ma method does not re eal
better in terms of memory 4 om
es
24l_J25[ ]26[ 27 Disadvantages: he disk, a large number of
; di st ri bu te
* Because the file blocks eae :ndividuall d ra nd om ly a linked allocation slower.
. list f y. This m at directly access the ae
seeks are ne eded to access ete or direct access. We | is
26_J20lJs0L2 oN
n sequential
: ly (sequen

* It does not support ee accessed by traversing inters.


ofa file. Ablock k ofa file oe of the file via block Po
access ) from the starting
34-2017 SixSixtth Semester, Operating Sys
tems
* Pointers required j n i ked allocatiati
the lin on on inc
i: ur some extrg Ny
3. Indexed Allocation | LP. University-[B.Tech
.|_A B Publisher
| °Verheag 1. block = index[pos/ 2017-35
2
SitaIn thiies oe eee 1024]
known as the Index block containg
2. offset = pos%1024
index block conta; pied by a file. Each file has its own index block, The ‘ae Point, Linked Index Block
iho aHaneae Allocation
ee ins the disk address of the ith file block. The directo, ‘ 1.Similar to linked file blocks but usine :
A entry
S of the index block as shown in the image: y Ntry ast)
9. Good for large files uy using index blocks instead of data blocks
3.Both random and sequential
access are easy
Cee _ directory 4.Random access is slow for large files
Q.8. (b)Why directory stru : cture is requ : ed? Dis
quir i yp
| file index block — directory structures along with respective merits and Mabie
OL) 149 2 3 jeep 19 Ans. a Tere a directory
Structure is the way an operating sy
a a
system an les are displayed to the user. Fil stem’s file
es are typically displayed ;
4 3 6 7 q hierarchical tree structure. er
There are many types of directory structure in Operating System.
They are as
follows
| a 9 (1) Single Level Directory
(2) Two Level Directory
(3) Tree Structured Directory
16Lla7LjisC hel Ie | 19} | ;z (4) Acyclic Graph Directory
(5) General Graph Directory
20 J 21 ael asl Ty Wg (1)Single Level Directory
In Single Level Directory all files are in the same directory.
24 [_]25[_J26[_]27 — Limitations of Single Level Directory
(a) Since all files are in the same directory, they must have unique name.
‘= 29|_]30 a7
(b) If two user call their data free test, then the unique name rule is violated.
(c) Files are limited in length. hdl
Advantages: Eve n a sing le user may find it diff icul t to rem emb er the names of all files as the
(d)
* This supports direct access to number of file increases.
the blocks occupied by the file .
fast access to the file blocks. and theiefors (e) Keeping track of so many file is daunting task
* | It overcomes the problem
prov4i des. at (2) Two Level Directory a
of e xternal fra
Disadvantages: |
hbo ‘ ‘s
ae has Its own User File Directory (
Tao. st ar t or us er log in, ; th e sy st em: Master File Directory (MFD)
en the user job j
y 6

(iii ) Whe
O
is in de xe d by us er na me or Ac co unt Number.
is searched. MED articular file, only hisis 0 own UFD D i is seare hed. |
ae
(iii) Whe n user refers to a part Orato aene’ To havea pattie ye fila
Thus different users may have file s wit! same and file NAMe.
y ‘rectory , we must give both tree the user
uniquely, in a two level directory. od of height 2
ve l di re ct or
, y ca n be a tr ee or an invunvert
Comaprison: A two le L
| is Ma st er Fi le Directory (MFD).
Index Block All The root of a tr ee
). Th e de sc en de nt s of UFD’s are
FD
ocation e User File Directory (U
ar
1. File block add Its direct descendents
resses file themselves.
2. Directory has a p the le av es of th e tree.
ointer to index blo _ The files are
3. Both random and se ck ve l D i r e c tory
. Limitations of T w o Le
quential accesg u s e r f r o m another.
4. .File size limi tation depends 0 “areLe easy st ru ct ur e ef fe ct iv el y 1s 0 lates o n e
8
The
he j index
inthe block then the maximu,, size f
Nn array file
« ne ree we have (ae pointe ae
A (3) Tree S t r u c t u r e d Di re ct ory
files or s ub di r e c t o r i e s . A\ l d irectories
blocks a.set of
KB assuming 1KB dat 5 A directory (or Sub directory) contains
th e s a m e in te rn al fo rmat.
has y d e f i n e s t h e entry.
ch di re ct or y e nt r
(i) One bi t in ea t e d i r e ctories.
ea te a n d d e l e
ll s ar e us ed to cr
(ii) Special ca
36-2017
Sixth Semest
er, Operating S
Bach pr eeess ha
4
ystems
. > “
s a current direc
'S that are tory. Current dir ctory
of c“utrrree
nt in terest to the process. e Sho
u Iq “Ona
(iv
Ie) ) When
|

ar bferanc .
€ is
, u The user chn change made to a file, the current directory is s earch
LEU Niversj ty-[
B Tech, }~
his current di rectory whenever he de \ why it is vital that staf
cnattne, whe sip f Members with System
file is hot needed in
the current directory So and upload ciiiue ace |
iY = path name or change tnen the user Usual There are several steps to
the current directory. * Meee nae be consider when train
4ths can be of two an active, Evolving proc
(a) Absolu te Pain types :- y "ty : bie yeorunderstand ess it response to operational needs
document with procedures sh
| *| ae z |tem ad ould be readily available for
Be
: gi
gins
ns at ro
. ot and follows a = maa umirni
eshould assign Correct le
path down to t he specified file vel of access to users ba
(b) Relative Path Pp j ie sed on
is
- Auditing Processes |
Defines a Path from curren should be put into pl
t directory. accountable for any inac ace so that individuals
_ curate data entered into can be held
(v2) Deletions ir dire | Data Validation Rules th e sy st em .
ctory is empty, its en
simply deleted. If it is not em try in the dir ectory
pty : One of the Two approach that Co a
(a)User must delete all the files in es can b Ntaing. place, there is always room for
the directory. human-error
ntry in their 9
(b)If any sub director : . | rules, administrators can ensure d
ies exist, same procedure must be appl
The UNIX rm co ied. Be
mmand is used. alteration, validation rules provide addition al
. security and data quality assurance - a
MS dos will not delete a directory unless it is
empty. natural requirement for accurate analytics.
(4) Acyclic Graph Directory ay Q.9. (a) An operating system only Supports a
| single directory but allows that
Acyclic Graph is the graph with ae directory to have arbitrarily many files with arbitrarily —
no cycles. It allows directories file names. Can an
and files. With a shared file, onl to Shargye g: ae approximate hierarchical file system be simulated? How?
y one actual file exists, so any (4.5)
Person are immediately visible to the another
changes Made } by i Ans. One way to simulate that is to append to each file name the name of
Implememtation of Shared files and di directory that contains it.
rectories an For example: UsrStudentsZivaPrivateFileX
G) 7 create a link sine fil 7
“Hierarchical File System” (HFS) is the file system used — ae eae
ce
A link is effectively a pointer to another
file or Sub directory. Macintosh hard disk. When a hard disk is paren a = a tae
Duplicate all the information about them an = archical file system is used to create a directory £ a Pras Oe ace
1 n both sharing directories
(ii) Deleting a link ae ice
O are added to the disk. Since HFS is a Macintosh fo >
* Deletion of the link will not effect th ves.
ann ot recognize HFS-formatted drives. icallyly formatted
W WindowWw s hard drives drives ar are typical
e original fj le, onl y link is removed ee using WIN32 or NTFS file systems.
To preserve the fi le until all references to it are =i
deleted. | oh i : ot originally designed to handle large hard disks,isks, such as the
ae eee as oe ein today,
dated file system
Apple aah eae a = allaes for smaller
ie x : r HFS Extended, with the release of Mac’ = Y file must take up. This
qual cluste nahi
ae sizes, which reduces the minimum size
ain data during collectig.

ty pe s of st ru ct ur es for file’s’s data,


ny
reported that data quali ;
ore than $600 billion annu ally. Yet decision-makers Q.9. (b) Some systems support ma Wha t are the advantages and a
simply
| support a stream of bytes.
hers
while others
ost disadvantages? ff
if er
fe en
re nt fi le st ru ct ur es 1sis that the
ion that translates into busing. a g e of h a v i n g th e s y s t e m support di
tability is data cleaning. anat
Ans. An addvavnt
ap

- different file struc tures, it


on. if the system provides the ae
-

support. In oe coon than an application. The


t the s ) presumably more omae
can implemen
n data integrity. Asa proactit
| e 0
; t be able to run on n Stsuch
and centralizes cleanup
1

; hat 1Sis provided


what by the iepeotem ne define no ne
projec ts in a single repository.}} file types one PIV
a

automating processes,
delegating tasks, an ee rating 8}
strategy i for The ries of bytes. Thisbare pla roac
Maintain data quality t d monito ring data cleanup,
hroughout its life-cycle. F
DIG hel systema 2 “d instead treat all cae the operating
ture for
_ Data Entry Training & Accountabjj; ae 7 ee ee The advantage approach is that 1) SIP. de the struc
© er has to provi
ty system no long file struc tures,
Data integrity Starts
at the source — the user vo Ma i - system supp ort for file systems: ees applications to define
errors that compromise analytical
; : Manual data entry can vba i} , Furthermore,
|
results meant to guide business different file types
m S
Ss.

decisions. Thal
38-2017 Sixth Semester, Operating Systems ;
alleviating the situation where a system
may not provide a file definition Fe 4
specific application,
Q.9.(c¢) Deseribe file access control mech e
anism. : an
Ans : Access control is a security technique that ca
ch

Can view or use resources in a computing


n be used to regulate yy
environment. , : a ty
There are two main types of access control: physical and logical. py...
control limits access to campuses, buildings, rooms SS
. . }
ie hy eat IT ASsety 1
, kets i : CQ)° le. ‘

access limits connections to computer networks, system


a

tiles and data, =” ty


The four main categories of access control are: CT eae t. f

* Mandatory access control ik


* Discretionary access control oe ae
* Role-based access control | 3 | an : a
* Rule-based access control ei
Access control systems perform authorization ee ease authentication . 2
approval, and accountability of entities through login credentials including passa 7
Ve
»

personal identification numbers (PINs), biometric peanad aero t= Bical or elec


reat F

TONIC ke,
i
i | sf ¢
Ne
|
tp.
F!

yt ; Re 7

7
rh t ,
[B.TECH]
. 1% hrs. LETCS-304]
30 MLM. :
Iwo te: Attempt Q.No. 1 which is compulso
ry and any two more questions from re
maining.
Q. 1. (a) How Timesharing is different from multiprogramming ?
(2)
Ans. Main difference between multiprogramming and time sha
ring is th t
E, ,ltiprogramming 1s the effective utilization of CPU tim
e, by allowing several ra a
“sp use the CPU at the same time but time sharing is the sharing
of a oldman facility
by several users that want to use the same facility at the same time. Eac
h user on a
=F time sharing system gets her own terminal and gets the feeling that she is usi
ng the
s |} cpUalone. Actually, time sharing systems use the concept of multiprogramming to share
the CPU time between multiple users at the same time.
Ae

Sh
ce24 9.1. (6) Differentiate between Internal and External fragmentation.
Ts

ay
r (2)
| _
+ Ans. External Fragmentation: Total mem
ory space is enough to satisfy a request or to reside a process in it, but it is not
| contiguous so 1t can not be used.
Ope rating system
se Process 7
Process 0 3

— . Process6 — | | | There is enough memory


SOA 7 we to run process 7 but the
— Process 2 — memory is not contiguous
<——— Externai fragmentation
Process 5 0

Process4 |

. | Internal fragmentation: Memory block assigned to process is bigger. Some portion


oe of mem ory is left unu sed as it can not be use d by ano the r pro ces s.

Internal
fragmentation

External
fragmentation

| | Difference betweey Internal and External Fragmentation |


si ze m e m o r y al lo ca ti on te ch ni qu e
t i o n oc cu rs w h e n a fi xe d
“fi Interna¥FYuipmenta i c m e m o r y al lo ca ti on te ch ni qu e is us ed .
cu rs w h e n a d y n a m
‘Sed. External fragmentation oc 1s as si gn ed to a pi —
cu rs w h e n a f i x e d si ze pa rt it io n
* Internal fragmentatio n oc 1n th at pa rt it i
k i n g th e re st of th e sp ac e
|
,

si ze t h a n th e p a r t i t i o n m a
j
"i with le ss

jp AP
a ar ——

zl
i 4 a

|
2-—2018 Sixth Semester, Operating System
adjacent orl . LP. University-(B.Tech]|-Akash Books
unusable. External fragmentation is due to the lack of enough Process
ause then ajj fr CR ay
loading and unloading of programs or files for some time bec ‘ty C€g Pay | CPU burst time |
:
Arrival Time
;
: re.
ant buted here and the P
distri 1
: 9
ed by com pac
.
tio n whe re the AaSSignea,.
.
P
¢ External fra gme nta tio n can be min 2 6
. : , so that contig ; s
uou spa ce :
18 841 ined. However, thi OP eratio
9S
ed bI
n we P 2
are moved to one side
;
s 4é 4;
time and also certain critical assigned areas for example system services can, ty
dis ks whe n running: t iy
obs erv e this com pac tio n step don e on har d
moved safely. We can 3
i ‘ Ps 2 4
disk defragmenter in Windows.
. External fragmentation can be prevented by uae th Sa oe Segment, i: Ans. (i) SSF
SP eiven While in realy tig, font
and paging. Here a logical contiguous virtual memory Preeee ce BT
files/programs are spl itted into 2spar ts and pla ced
res
here8 and theFoe 4 Ytthe aE AT.
I —l=2=1=1-1=x 9
Several size, |
e Internal fragmentation can be maimed by mijn ner ) Po 6-1=5x 9
erna agmentation;,
assigning a program based on the best fit. However, still int
od? Kixplai ae i Ps 4—1=3-1=2-2=x 4
fully eliminated. 6
- xplain with diagran, Poi? 5
Q. 1. (ce) Why medium term scheduler is require
g
Ps 2%
(3)

d Te rm Ex am in at y on, May -Ju ne 2017, P.No.- 22-2017.


Ans. Refer Q.no. 4(c), En } Py | Py | Pa | Po | Ps| Ps | Ps} Ps | Pe | Pe |
oe 2
0 1 2 3 4 5 6 8 17 15

Waiting time > for P, > 0, P, > 6 +3-2=1,P,> 4-—4=)


P,715-6=9,P, >8-8=0

Avg. waiting time > O+74+05 +9+0 _ 465 3.2 unit time.

for P, 3 0+3=3
Term around time —
P, —> 7 i 6 = 13

P, > 9+ 5 =14
P. +0+2= 2
x, Ave. LAT = 36/5 = 7.2 unit time |

ae 2 . of arr: ival | on =the basis of arrival time.


| | (2) | (ii) FCFS: First be find sequence
an d di sa dv an ta ge s of mu lt it hr eading.
Q. 1. (d@) Explain advantages
/ | . | P Pe \ es Bemba 20
Ans. Advantages
Q” "AS 09 ss: M eos
© Thread switching does not require Kernel mode privileges.
e User level thread can run on any operating system. a So. Waiting Time for P,70,P,> 3-2=1,Ps . | ‘ Ss a

¢ Scheduling can be application specific in the user level thread. | Pp, b- eyo
. , e.
4.6 Unit-tim
are fast to create and manage.
Jae | = oye . sete {0
ae e Us
zaer sis ae
ae Avg W.t = a
* Ina typical operating system, most system calls are blocking. | +s foe BO +3=3
¢ Multithreaded application cannot take advantage of multiprocessing. Turn around time . age
Q. 1. (e) What is thrashing ? Explain why it occurs. (2) | | | 2 +» 5+4=9
Ans. Refer Q.no. 2(c), End Term Examination 2017. P.No.- 16-2017. oe ) »71+5= 12
-
| : 4
; er Pp? 10+2=12
Q. 2. Consid the set of processes P, to P, with the following CPU burst |
time.Find the average turnaround time and waiting time for Shortest Remaining |
job First and FCFS scheduling techniques. | (10) |
Sixth Semester, Operating System |
4—2018 LP. University-[B -Tech|-Akash Books
2018-5

> 3474941
: 2412 = 48
= =86 Unit time. : . . 4.4 process contains a logi
cal address space of 4050 bytes. Main memory
Avg of of t.0. t. age 1S oe bytes. If the process is divided i nto fixed size partitions of 16 byte
pic” (10)
Q. 3. (a) Why are segmentation and paging sometimes combined int | (a) What will be size of offset/displacement bits?
scheme ?Explain with suitable diagram. * (b) How many pages are there in the process?
a
Ans- Segments can be of different lengths, so 1618 harder . ae ce - Asan, | (c) How much internal fragmentation will occur?
in memory than a page. With segmented virtual memory; oe fi sical tone S of yj E (d) Find out number of entries in general page table.

ges
memory but we still have to do dynamic storage allocation of phy Ory. In op (e) If the page table in inverted one then how many entries will be there?
; ing
paging
into a two-0-leve] Vittyy
ah) | |
to avoid this, it is possible to combine segmentation and = 24
: pa ge table for that advsegmen; Ans. (a) Page size = 16 byte
memory system. Each segment descriptor po in ts to
ment) with some of the anta Go, number of bits in page offset is ‘4’.
give some of the advantages of paging (easy place Be9 (b) The no. of page in the process
segments (logical division of the program). | ae
such as aa at thy) = 4050/16 = 253.125 = 28
Paging is a virtual memory scheme which is ods tlecka
Yteg, | (c) Page size = 16 byte. process size = 4050 byte
‘din |
application level and which divides memory into i Fae So. no of pages = 253 pages + 2 byte. So internal fragmentation
The segmentation memory management scheme PO rane

ee
using segme e size, = 16-2 =8 byte.
burden on the applic ation, and refers to memor y
ica l uni t vis ibl e to the use r’s pr og ra m and id of arbitary Size (d) No. of entries in page table = No. of pages, the process divided,
Segmentation is a log
uni t inv isi ble to the use r’s vi ew an d is of fixed size so no of entries is 2.
whereas paging is a physical
(e) No of page = 2° |
bit.
trap So the no. of bits required to identify each page = 8 |
— 210 /94 = 9® ,
2
no o. of fr am es
numbers 8 pr es en t in each frams:
wil l st or e pa ge
-segment table > inverted page table we
STLR . nu mb er s of en tr ie s will be 8:
so the
3 yes > :
STBR PTBR

S : :
: physical
CPU -}—*® (sd) page ieee memory

E p
(p,0) f -— (f,0)
|
Q. 3. (6) Calculate total number of page fault that will occur while processing
the page reference string given below : 4,7,6,1,7,6,1,2,7,2, using LRU page
replacement policy, when page frames are three. , 6)
he the Be ae e vv

41f4] [4] [1] [1] [1] fal fay fa] fa


Ans. Ti 7 (ig ya ea ee
6//6//6/ 1/6] |6//6)/7] 17

x x x x

So total no. of page faults = 6.


LP. Univers
ity-( p tT ch|-Ak
» The output ash Books

END TE RM EXAMINATIO N F re cu e 20 18 , c
of this p
ode/data in
RAM.
2018-7

SIXTH SEMESTER [B.TECH]


cation of

OPERATING SYSTEM [ETCS-304)


Time: 3 hrs. My.
1 which is compulsory, Selecs 6neg 4‘f
Note: Attempt five questions in all including qQ
: . ; ‘ . No. 3

from each unit. |

Q.1. (a) Differentiate between interprocess von nUnicatigg ay -


synchronization with example.
tae ism for processes tog, MMi _—*Y [In a paging based System, address bj
Ans. Interprocess Communication (IPC) Mechanism
and we saniedbian their actions Message sy Sune facility provides sat With ¢ |
other without resorting to shared a
ceive(message) If P ; craton fram
send(message) — message size fixed or vena Iso populated with correct frame number.
) tion link betweeeen
cation tisk a
em QexChaty
Wish,
communicate, they need to establish a communica : Now coming back to address binding, the logical address
messages via send/receive. Implementation of communication. Physical (e ‘Bs Shang 8 generated by CPU is divided
into two parts:
memory, hardware bus) logical (e.g., logical pr operuice): | | |
enemies seation Message passing may be either blocking or nonblceking Blo chin e Page Number (aka virtual page number)
e Offset or displacement within the page.
is considered synchronous Blocking send: the sender blocks until the ae 18 Teceiyei
by the other party Blocking receive: the receiver block until a message is available Non Page number is used to index into the page table, to get the corresponding physical
blocking is considered asynchronous Non-blocking send: the sender sends the Messap,| me/page number. The physical page number is them combined with the offset to get
and continues executing Non-blocking receive: the receiver gets either a valid Messag, a complete physical address.
_or a nul] message (when nothing has been sent to the receiver) Oftenac Ombination,| Next is segmentation. In this scheme, the process is allocated memory in the form
Non-blocking send and blocking receive
Example Concurrent access to shared data may result in data inc of sepmen. 3
Code/Text Segment - containing
ee
instructio
. 3 .
ns to be : executed
onsisteney |
Maintaining data consistency requires mechanisms to ensure the orde
rly e Xecution of Data Segment - containing the program’s global and static data.
cooperating processes. Suppose that we wanted to provide a solu } sts for the process.
tion to the N producer. ) eap - - space | used to service : dynamic : memory allocation reque
Heap
consumer problem: We have a limited size buffer (N ite
ms). The producer puts data
into the buffer and the consumer takes data from the Stack - space to be used during function calls.
buffer We can have an integer _— — — at - — LOCcess..
count that keeps track of the number of occupied All these se gm en ts to ge th er fo rm the ph ys ic
} al
buffer entries. Initially, count is # ——.
0. It is incremented by the producer after settp | ‘cal to physic al ad dr es s ma pp in g is don e th ro ug h a se gm en
it inserts a new item in the buffer
decremented by the consumer after andis ee : se gm en t nu mb er ass ign ed by the loa der . Asegment table is
it consumes a buffe ritem’ \ en
es as an
DIN-1] outt in? b{0) b{1] b[2] b(3] [4] ... bEN-1] int out!
b[0] b[1] b[2] b[3] b[4} .. Se tlioaine information about each asecment
Q. 1. (6) Briefly explain
the role of complier, loader
| ¢ Se gm en t Li mi t - Th e off set ran ge wit hin the segm oe
hardware in the fo and memory management h segmen
llowing addre ss bind
ing schemes : ent Base - The starting address of eac
(Z) Compile time bind (4.5) |
ing
(ti) Load time bin
ding « Segment number.
(tit) Run time bindin
g, ithin the the sese
gm gm
en t. ent
values
e Offset or displacement wi into the segment table to get th
e
of segment
me
Segment number is used to ines 00 the range (0, limit]. If so, va
ne of
limit and base. First we cae oe

segment base is added to the olts <= the real physical memory pe |
e . ‘> in
segment. the context of
ion-time address binding 10 : |
I hope the above exp
| hemes.
diffe rent t
memory managemen s¢
The logical] addres
s unde
unit in particular
e r , O p e !s r a
a ttiing ©OyYovois
S; emest e
g-2018 T

address binding ca be further classifieg int, LPy. UnivUneivrerss;ity-


Apart from execution-time, (B,Te ch|-Akash Books
that the semaphore val
different types: ] en s Saks ote |
at the time CXen,
ue is not ain

ys ic al ad dr es s resolutiol 1 ‘thahe pptens


hy waiting, the process ean block ;
Load-time: logical to ph ee ly, all the logica queue associated with th eock itself. The block op
nt yf oth et d cad aox cu uitiBon eneat
program 1S loaded into main memory. Subseque e sa os tr ool ec waiting state. Then, con
the
Semaphore, and
l to ph ys ic al e p e
by the CPU are identica ! a. Th e di ffe bn )
e lo ca ta bl e 4 ‘ Vo ss a l b a n i a 4
binding, the executabl has re e ad dresseg to amt)
er tr an sl at es
is that in this type of binding, load at io n ha pp en s at ru n- ti me or dynamicay
es se s w h e r e a s th is tran sl
physical addr
execution-time binding.
ti me we do n’t know where exactly the
mpil o th e re a] meet
Compile-time: Usua lly at co But in case it is k n o w n ,
hysical mem ory.
is poing to reside in the p
ge ne ra te d at t he com pil e tim e. Aga in, the logical addres ses Sieg
addres se s ca n be it
ar e 8
virtually im Possibley
| Co mp il e- ti me bi nd in g ma ke s
as physical memory addresses. at co mp il e- ti me ) resident in the Memon
programs (wit h bi nd in g do ne
have two different
at the same time.
Seek Time , rotation al late|ncy, and constant angular velour
Q. 1. (c) Explai n "Velocity
(3) | be the followi ng allocati on algorit hm
disk arm toa x a ® Descri fit : (5)
Ans: Seek Tim e: See k tim e 1s the tim e tak en to loc ate
he du
the
li ng al go ri th m he a (i) First fit (di) Best fit (ii) Worst
a dor wri te. So the dis k sc
track where the data is to be re Lives | - Ans. (t) First Fit
tter.
minimum average seek time is be In the first fit approach is to allocate the first free
tational La te nc y: Ro ta ti on al La te nc y is th e ti me ta ke n by the desired secto partition ee hole largf'ge
enou gh
Ro which can accommodate the process. It f i n i ;
disk to rotate into a position so that it can access the read/write he&d
s. So the ia {
partition. nishes after finding the first suitable free
scheduling algorithm that gives minimum rotational latency is better. Advantage

Q. 1. (d) What is the difference between Semaphores and Monitors ? Explain


Fastest algorithm because it searches as little as possible
with suitable examples. Qs) Disadvantage
Ans. Difference between Monitors and Semaphores
The remaining unused memory areas left after allocation become waste if it is too
Both Monitors and semaphores are used for the same purpose-thre
smaller. Thus request for larger memory requirement cannot be accomplished.
synchronization. But, monitors are simpler to use than semaphores because the ie
all of the details of lock acquisition and release. An application using sema e : (ii) Best Fit
to release any locks a thread has acquired when the application tonminates ea The best fit deals with allocating the smallest free partition which meets the
of
requirement of the requesting process. This algorithm first searches the entire list
~“

done by the application itself. If the applica ti do . then a


this, 3
be
el ppli cati on does not tries to find a
that needs the shared resource will not be able to proceed. ee free part itio ns and cons ider s the small est hole that is adequ ate. It then
Another er diffdifference when using semaphores is that every routine accessing a shared — hole which is close to actual process size needed.
eh rie
source has to explicit ly acquire a lock before using the resource. This can be easily Advantage
forgotten when codin g the routines dealing with multi ch bet ter tha n firs t fit as it sea rch es the smallest free
ultithreadini g. os Memory utilization is mu
semaphores, automatically acquire the necessary locks Se ee partition first available.
Q. 1. (e) Define the ; ovate
| -

Disadvantage
a te *,¢6

altogether? Explain your ant waiting. Can ‘busy arqiteg)) wi th ti ny us el es s ho les.


me mo ry
It is slower and may even tend to fill up
. (2.5)

Ans, Busy waitiny


:
| |
a tight loop without oe a a process is waiting for a condition to be satisfied in (iii) Worst fit at th e po rtion
es t availa bl e fr ee po rt io n so th
relinquishing the see the processor, Alternatively, a process could wait by t a p p r o a c h is to lo ca te la rg
*or, and block on a conditions and wait to be awakened at some In worst fi is th e re versofe best fit.
g en ou gh to be us ef ul . It
. e future. re left will be bi
associated with putting ap Busy waiting can be avoided but incurs the overhead }
roces : Advantage
program state is reached. 6 a sleep and having to wake it up when the appropriate u c t i o n of s m a l l g a p s.
Reduces the rate of pr od
)
busy Y waiting,
wai we can modify the definition of the wait and Disadvantage st ag e th e n it ca nn ot be
signal semaphore operations r y a r r i v e s at a later
qu ir in g la rg er mem o
4 process executes the wait operation and finds If a pr oc es s :re t an d oc cu pied.
est ho le is al re ad y sp li
accommodated as the larg
10-2018 Sixth Semester, Operating System
Q. 1. (A) Define the criteria of comparison among CPU scheduling alg “a )

Ans. There are many different criteria’s to check when considering the Ans. Paging is implemente 4 2018-11
by breakin
scheduling algorithm : tis most efficient to break th ‘Ng up an address into 4 page and
erform arithmetic on the © address into X page bits and Y idle
1. CPU utilization: To make out the best use of CPU and not to waste
cycle, CPU would be workin| g most of the time
| (Ideally 1000%% ofof the the titime). Cons a) Cby
ide
real system, CPU usage should range from 40% (lightly loaded) to 90% (heavily load
2. Throughput: It is the total number of processes completed per unit + Y
rather say total amount of work done ina unit of time. This may range from 1O/seey.” Pe cvcvcccccvrete oeh eS ev ese sedinadunctbes WP ot
ek delcscdetcnc,
to 1/hour depending on the specific processes. nd | Page number (n
bits) | byte offset S
au
3. Turnaround time: It is the amount of time taken to execute a particular Pre of cacataccesduaaO
eeE
ceE
tec +
i.e. The interval from time of submission of the process to the time of completion of 88,
process(Wall clock time). the
4. Waiting time: The sum of the periods spent waitinga in the ready queue
of time a process has been waiting in the ready queue to acquire get control on theAmMOunt
Cpy
|
|
5. Load average: It is the average number of processes residing in the ready q
ueye
waiting for their turn to get into the CPU.
6. Response time: Amount of time it takes from when a request was subm itteq
|
until the first response is produced. Remember, it is the time till the first respons 8 and
Q. 4. (a) In the context of process schedulin
not the completion of process execution (final response). : :
starvation occur under the following aateaiauce what is the starvation? ~
In general CPU utilization and Throughput are maximized and other factors
are (i) FCFS (ii) SIF
reduced for proper optimization. (iii) SRTF
(iv) Preemptive priority based (v) Round Robin.
UNIT-I 3 Ans. Starvation is the phenomena in which
Q. 2. (a) Discuss the various memory management schemes. (6.5) a process is not able to acquire the desired
resources (like processor, I/O device ete) for a very long time to progress with its exe
Ans. Operating system versions Vista SP1 and Windows Server 2008, impleme ted cution.
This can happen due to drawbacks of scheduling algorithms. Scheduli
new technologies, for both resource allocation and security. Several of these new ng algorithms
are used to decide to which process the resource(s) needs to be given next. Example:
technologies include the Dynamic Allocation of Kernel Virtual Address Space (including
e In Shortest Job First Algorithm, if there is a process with a rather large CPU
paged and non-paged pools), kernel-mode stack jumping, and Address Space Layout
burst waiting for its execution and a stream of processes with smaller CPU
Randomization. Basically, the allocation of resources are not fixed, but are dynamically
burst keep entering the ready queue (a queue consisting of those processes which
adjusted according to operational requirements. The implementation of these new
technologies such as Address Space Layout Randomization are mostly due to the are ready to execute), then the CPU will always be allocated to the process with
hacker the shorter CPU burst and there is a probability that the process with the large
threat of an advanced knowledge of the location of key system components
(such CPU burst might never get the CPU to complete its execution and starve.
as kernel32.dll, ntdll.dll, etc), and are partly due to the Window’s goal of
using memory e In Priority Scheduling, a constant stream of high priority processes might starve
allocation more efficiently by allocation on an as needed basis.
In order to understand one or more lower priority process(es) as the CPU will always be allocated to
these new technologies better and be able to use them as a dev
eloper, device driver writer, the process-with highest priority. |
or systein’s administrator, |
x
Waiting for something that will eventually happen (in deadlock it will never happen).
First-Come First-Serve Scheduling, FCFS ha
is very simpl e - Just a FIFO queue, like cust omer s waiting in line at the
¢ FCFS
bank or the post office or at a copying machine. Be
¢ Unfortunately, however, FCFS can yield some very long a =
- particularly if the first process to get there takes a long time.
Q. 2. (6) Explain difference between consider the following three processes:
internal and external fragmentaliaas Process Burst Time
| 24
(3) Pl
Ans. Refer to Q.1 (b) First Ter :
m Examination 2018 Pa. .
Q. 2. (¢) Why page size is always a
: 9 , : )
pages, frames and page table
? npn ar ri veos i e
fir st. Th e av erag e waiting
a? Ie PARAS scheming. Maes 8)
G a n t t <ch ar t be lo w, pr e cess Pl
. first 44+27)/3=11
5

r th e t hr ee pr oc es se s is (0 + 2
ae fo
12-2018 Sixth Semester, Operating System
In the second Gantt chart below, the
time of (0 43 4 6 )/3=3.0
same three processes have an ay LP. University-{B Tech|-Akash
Books SH’s
:
same, but in the second
ms. The total run time for the thr
My e Q Ure “Tagg estimate[i+1}= alpha * bur stl i
, S .
case two of the three finish ts) ie
process is only delayed by a short amount. much quicker. and th ty
: * Oh
P, P, | fi
0 3 6 7
FCFS can also block the
system in a busy dyn amic
as the convoy effect. When one CP system in another Way
U intensiv
of I/O intensive processes can get backed e process blocks the CPU, 5 Ry
wae up behind it, leaving the 1/9 4 be
idle. When the CPU hog finally relinquishes the CPU, then the VOOdie.
pass through the CPU ; ;
quickly, leaving the CPU idle while everyone r >i |
tte,
for I/O, and then the cycle repeats itself when the CPU inte ‘ Ueg
back to the ready queue.
Shortest-Job-First Scheduling
, SJF
* _ The idea behind the SJF algorithm is to pick the quickest :
needs to be done, get
fastest little
it out of the way first, and then Pick the next JOb tha
fastest job to do next.
ae |
Sm al le g, |
* (Technically this algorithm picks a process based on t he n
ext shortest CP
burst, not the overall proce
ss time.) y
* For example, the Gantt chart below is based
upon the following CPU burg
times, (and the assumption that all jobs arrive CPU burst (2) C74) 6.4. @ “W
at the Same time.) -x
Process "quess"(t) 705 6 6 6 §: 9 WR
Seis: Burst Time
ir | 6 Figure -- Prediction of the length of the next CPU burst.
P2 8 SJF can be either preemptive or non-preemp
- ?
tive. Preemption 7 when a
occurs
a} apts 7 new process arrives in the ready queue that has a predicted burst time shorter
P4 than the time remaining in the process whose burst is currently on the CPU.
| 3
Preemptive SJF is sometimes referred to as shortest remaining time first
scheduling. 3 | |
LEONA LORI eae
& SS ee ORTne .
Oe
eS <>
hk
Taig " Ee . St
eae
For example, the following Gantt chart is based upon the following data:
Process _ Arriv‘ al Time
i t Time
=
ge wait time is (0+3+4+9+16) 0
opposed to 10.25 ms for FCFS /4=7.0 ms, (as Pl ;
for the same proc esses. )
P2 ‘
P3 5

ving to re-submit the job if they set the limit


! ,
Interactive system. ot work for short-term CPU sche Brice aoe 28
duling on an ae
e Another option would be |
|
Oe
-+
. 10-1)+(17-2))/4 =26/4 |
to St at is ti ca ll time in this case is ((5-3) +( ;
characteris y measure the run time for non-p reemp tive SJF or 8.7 5 for FCFS.)
; ms
= 6.5 overe
one ms. at (As opp eo
Se ae: d
Prior ity Scheduli:ng .< a more general case of SJF, in-_. — whic . each job is (GIF
a faret. assignvee
e
* Priority scheduling 182 th the highest priority a sesoriky . The smaller the
a erie ) sead0 DAE expected burst time as 14 F ‘
the inver | ority.) thin a fixe
expected burst, the higher the Pe 2 Jemented using integers W" priorities
he th er “hiich
gh” ” prio
ice, prioaritipo convention as to W
No te that in eeMs
range, but the
*

re 1s n© 3 a
; e
es eee

Sixth Semester, Operating System

14-2018 ere or small numbers. This book uses low number for be
use large en 0 being the highest possible priority. Igh
pee 'e. the following Gantt chart is based upon these process burst tj
time of 8.2 ms: Mes
> =a S HerTtiOss and yields an avereee wae
Process -Burst Time Priority

Pl 10 3
P2 1 1
P3 2 4
cach© process gets 1/nth of the processor time‘ude
r -se Borithms
P4 1 5 and shar Ifit is y
P5 5 2 wf, a real SY
stem invokes overhead for every context sy

He5 eoyantum
petween 10 and 100 milliseco
ads
nds, andare.context
Most
swine =m
qu 4 microseconds, so the overheais
d small relative tithes oo on the order
0 1 6 AAG 18 19 of process time = 10 .

e Priorities can be assigned either internally or externally. Internal Priorities


12
are assigned by the OS using criteria such as average burst time, ratio of CPy
to I/O activity, system resource use, and other factors available to the kernel
External priorities are aSsigned by users, based on the importance of the fob.
fees paid, politics, etc. |
Priority scheduling can be either preemptive or non-preemptive.
el es
Son?
BS eS
hs R oe kg
ee
ha
ee
oe dees
ee sees
i

Priority scheduling can suffer from a major problem known as indefinite


4, Roe | ee ee
.F- g a Lak eei | ——o = Eoie
oh < j
7 —ain ee - - a oe +>
s: : —+ ‘ ea. ~~ ae a
. “ mst FF

blocking, or starvation, in which a low-priority task can wait forever because | o- -3 5 9 10


there are always some other jobs around that have higher priority. Fi gure . The way in which a smaller time quantum increases
If this problem is allowed
to occur, then processes will either run eventually context switches.
when the system load lightens (at say 2:00 a.m.), or will eventually get lost ound time also varies with quantum time, in a non-apparent manner.
{Turn ar showin Fig.
n
when the system is shut down or crashes. (There are rumors of jobs that
Consider, for example the processe s
have been stuck for years.) | :
.

q >4 :
:

ao
ar
+

-
Se=>
=
~
S.
a
Wo. y
Se
“<p,
-. ~e
Jie
on

be
.
Fos
“2S
'

. < ea 5 Om et * ET ya:
. 4 ws t * 7

> One common solution to this problem is aging, in which priorities of jobs
12.5 bs
7 2? - -s . : ail 2 so!
og tee ae a
- a - rs
roa ~ on &
7

increase the longer they wait. Under this scheme a low-priority job will
7 e Lad a

eventually get its priority raised high enough that it gets run. | 12.0 ey

Round Robin Scheduling © te tides


=a
j= 1S a
Round robin scheduling is similar to FCF'S scheduling, except that CPU bursts =
N
ers ha
as
Oo
are assigned with limits called time quantum. = 11.0 : “a ; . Wee pcre!

oO WA pe ER. ak
When a process is given the CPU, a timer is set for whatever value has been set
for a time quantum. ex 10.5 Ree
ke Sake 8

oO If the process finishes its burst before the time quantum timer expires, SoO 10.0 PaesSere bana
chen it is swapped out of the CPU just like the normal FCFS algorithm.
SaaS ED
D
_ ~
aes ~ '
i Suk
mend
Dees
a .

=c 9.5 Fe en LBs ss
If the timer goes off first, then the process is swapped out of the CPU and
by poe *s : yore |

eee a a
°

moved to the back end of the ready queue. : |


ad te >>* ee : < aed

; a ax Ss , Pot a

The ready queue is maintained as a circular queue, so when all processes have
YEO RS Sve es i > rs
fe e bs ee
had a turn, then the scheduler gives the first process another turn, and so on: ToC es
RR scheduling can give the effect of all processors sharing the CPU equally, Geo"

although the average wait time can be longer than with other scheduling vantum the time 484 *
algorithms. In the following example the average wait time is 5.66 ms. . und time ' | 7
|
Figure - The way in which turnare
a
~aN es =) i Dee

16—2018 Sixth Semester, Operati


ng System
LP University-(B
e In general, turn Aga Tech|-Akash
Books 2018-17
CPU burst withi [ Process Id .

Priority
.

> ti Arrival Time Burst Time |


ms bursts each, the a 1 2(L) 9
verage turna round ti
10 ms quantum it re me for 1 ms quantum ig 99
duces to 20. H owever, if it is ma ; and foy
2 6 i 1
de too large, the 7
degenerates to FCFS 3 3 2 3
. A rul € of thumb is that 80%
smaller than the t
ime quan tum.
of CP U bu rs ts
. RR jug
Shoulq be 4 5 ;
S
hortest Remaining Time Firs
: , 5 4 jj :
t (SRTF) Scheduling Algorith
2 © . .

amis Algorithm is the Preemptive m 6 10(H) 5 15


version of SUF scheduling. In SR 7 9 15 g
execution of the process can be st Tp
opped after certain amount of time GANTT chart Preparation

FI am
evety process, the short term schedule . At the reine
r schedules the process with the least
burst time among the list remaj,: : a1 ¢ P3 PS Ps P2 7
of available processes and the runnin
Once all the processes are available in the
g process.
ready queue, No preemption wil] b
oe 2 3
10 16 22
Ea
39 45
done and the algorithm will work as SJF Avg Waiting Time = (04+14+0+7 +1+25+16)/7 = 63/7 = 9 units
scheduling. The context of the procegs ig
in the Process Control Block when the pro selva starvation or indefinite blocking is phenomenon associated with
cess is removed from the execution and the the Priority
duling algorithms, in which a process ready to run for CPU can wait
next process is scheduled. This PCB indefinitely
is accessed on the next execution of gche of low priority. In heavily loaded computer system, a steady stream of higher-
this Process.
Example: In this Example, there are six jobs P1, P2, P3,
P4, P5 and P6. Their arriya}
pecause
rority processes can prevent a low-priority process from ever getting the CPU.
time and burst time are given below in the table. Pq.4. (b) Consider the following set of processes with the length of the CPU
rat time given in milliseconds:
Process | Arrival | Burst |Completion | Turn Around Waiting Respon , P - Process burst time priority |
ID Time | Time Time Time Time Time e Pl 10 3
1 0 8 20 20 12 0 P2 1 1
2 1 4 10 9 5 Tots P3 2 3
3 2 2 4 2 0 2 Pp4 1 4
4 3 1 5 2 1 / 4 P5 3 2
5. 4 3 13 9 6 10 m The processes are assumed to be arrived in the order pl, p2, p3, p4.and pd
6 5 2 : |
7 2 0 5 all at the time 0.
4 Avg Waiting Time = 24/6 . (;) Draw the Gantt chart illustrating the execution of these processes using
Preemptive Priority Scheduling: FCES, SJF, non preemptive (a small priority implies a higher —
| (4)
In Preemptive Priority Scheduling, at the time of arrival of a process in the ready
Round Robin quantu=m1 scheduling.
process for
queue, its Priority is compared with the priority of the other processes present in (ii) Calculate the waiting time and turn around time for each
the (2)
SRTF strategy.
ready queue as well as with the one which is being executed by the CPU at that point of
time. The One with the highest priority among all the available processes will be given Ans. (i) Gantt Chart FCFS:
the CPU next. D4 P2 | P3 | P4 PS
The difference between preemptive priority scheduling and non preemptive priority ; 10 1% 13 14 N
scheduling is that, in the preemptive priority scheduling, the job which is being executed
SJF:
can be stopped at the arrival of a higher priority job. :
Pt
Once all the jobs get available in the ready queue, the algorithm will behave as non- p2 | P4 | P3 PS { 19
preemptive priority scheduling, which means the job scheduled will run till the completion 6. 4, enone :
and no preemption will be done. Non-preemptive
; priority eat
— 4
Example:
P2 P5 )
oe
—_—_—— "46 18 19
There are 7 processes P1, P2, P3, P4, P5, P6 and P7 given, Their respective priorities,
Gt Bi the |
Arrival Times and Burst times are given in the table below.
aN
Sixth Semester, Operating System
18-2018
RR (quantum = 1)

Pt P2 P3 P4 PS P17 P3 PS P7 a, P41 P5 P41


z
4
3 A 5 G 8 9 10 1 12 13
\

(i?) Turnaround time = finish time - arrival time


OR: Turnaround time = CPU burst time + wait time
the fir st la w (T ur na ro un d ti me = fin ish time —
By tius ingfrom Gantt chart:
fin ish me

Turnaround time
FCFS RR SJF
Pl 10-0=10 19-0=19 19-0=19
P2 11 2 1
P3 13 7 4

simila solutions are found in mot operating stems


P4 fo
14 4 2
P5 19 14 9 6 textbooks. : are renditions of the original treatment
ee Dijkstra, which motivated the semaphore
Waiting time = Turnaround time ‘ CPU burst time. mechanism he was
“is, -troducing in his original article..A\emph{semaphore}
is an
Waiting time ald integer OF boolean value, S, with two associated atomic operations:
FCFS RR DOWN(S) wait until S > 0, then decrement S:
SIF . Priority_
UP(S) increment S
Pa 10-10=0 19-10=9 19-10=9 16-10=6 =
In time-sharing systems, “waiting” is implemented by the operating system, which
P2 10 1 0 0
P3 11 5 2 16 | may put processes on a wait-list for later execution. In hardware, “waiting” may be
a omplished by busy-waiting or by some form of explicit signaling, such as token passing.
P4 13 3 1 18 Produce Consumer Problem: A producer process produces information that is
P5 14 9 4 1 b y a consumer process. For example, a print program produces characters
c o ns um ed
8.2 | o n s umed by the printer driver . A compiler may produce assembly code, which
Average waiting 9.6 5.4 3.2 that a re c
u me d b y a n a s s e m bl er. The assembler may produce object modules, which are
time is cons
|
consumed by loader. nt ly , we must have
Q. 5. (a) Describe Producer Consumer problem and Dining philosopher ns um er pr oc es se s to ru n co nc ur re
To allow producer and co em pt ie d by the consumer
problem with its possible solution. (6.5) be fil led by th e pr od uc er an d
available a buffer of items that can er 1s co ns um in g an ot he r ite m. The
Ans. The Dining Philosophers problems are a classic synchronization problem A pr od uc er ca n pr od uc e on e item while the co ns um
do es no t try to
so th at th e co ns um er :
(E. W. Dijkstra. Co-operating Sequential Processes). an d co ns um er mu st be synchronized, S o e mu s
producer
pr od uc ed . In th is si tuat io n, the consumer
Dining Philosophers: There is a dining room containing a circular table with five s um e an it em that ha s no t yet been
In the
con
chairs. At each chair is a plate, and between each plate is a single chopstick. wait until an item is produced
.
| no pra cti ‘cal limit on the
osophers who umer probhile m pla ces
middle of the table is a bowl of spaghetti. Near the room are five phil e d-bu ff er p pr od uc er co ens e e can
and need to eat 80 Th e un b o un d
oe : w items, but the producer
spend most of their time thinking, but who occasionally get hungry . Th e co ns um er ma y roblem assumes a
size of the buffer .items. The bounded-bauffer pro rod uce r-c
-rt ons
he umefer
buf rP is empty, and the
they can think some more. uc e ne w cue
ble, pick up the two cho pst ick s to the always pr od
In order to eat, a phi los oph er mus t sit at the ta e
tti on the plate. fixed buffer size. In
left and right of a plate, then serve and eat the spaghe mu st wa it if th e buffer 1S full.
rep res ent ed by the fol low ing pse udocode: producer
Thus, eac h phi losoph er is
process Pi] Q. 5. (6) Show how you
| .
semaphores. =
while true do y s e m a p h o rs
Ans. Use tw o bi na r
{ THINK; ting ae ath
as th e integer variable 1m the coun
PICKUP(CHOPSTICKU], CHOPSTICKl[i+1 mod 5]); _ o ck w h i l e up da ti n g th e i n teger
in te ge r | yari‘a
ad hle value
mutex l
EAT; k e pr oc es s de pe nd ing oP Nees:
), CH OP ST IC KI i+ 1 mod 5]) bl oc k/ un bl oc th
PUTDOWN(CH OP ST IC KI Ii
=<
=~
99-2018 Sixth Semester, Operating System
LP. Uni
* Binary semaphore: A binary semaphore acts like a mutex lock. Its definit; University{B Tech|_Akash Books
Oj, A deadlock situation on
shown below. h an a
wait(S)t | ere ae ee in & opukems: Tse if and only if all of the following
1. Mutual exclusion; At |.
while(S<=0) | : ; ast one resource
otherwi se, the processes would not be preve must be held in a non-shareable
nted from using th Mode.
-//
- J] bus}
busy wait nly one
e
P
process can
use the resource a © resource whenpn:
S-+; Or resource holdin - 4 4
T 1 ga process j curr
fe a and dina additional resources which are being helaby a at least one mt)
. : o preemption y ot
signal(S){ | , - it : @ resource can be released only voluntaril, bi .. ,
| poldiné : wal 4 ¥ dy the process
if(S==0)
=
4, Circular wait: each process must be waiting for a resource
S++; by another proc
: ess, which in turn is wai ing for the first process wean ne held
al,there is a set of waits € resource.
In gener waiting
; processes, P = {P pl gigt }
resource
for tine for a resource P,, P, Bs is P,waiting & ¢, lor a resource held byw, P,Such
held by held so ‘a Pis'waitin
and that nis P. .
Implementation:
1. CSem(K)
3 es { // counting semaphore initialized to K Theseeosfour conditions are known as the Coffman condit:
nditions fr
2. int val < K; // the value of csem ses sai Miacaee Edward G. Coffman, Jr. En eee iret
| ? : rthe i
3. BSem gate(min(1,val)); // 1 if val > 0; 0 if val = 0 Q.6 onNowing snapshot ofa system:
4.: BSem mutex(1); // protects val | es Available a]
) A Ee RY A. Be Bee c D |
6. Peles){ | PO © a ey eee e eee cee
7. P(gate)
| | :
| |
| | Lass
p2
21 3
eae ere |\\ ee eee 3 4 a. 223856
: me — | z Re. ps | 0 6 3 2 0 G39
. val< val—1; | 0 0 1 + S- 6.28 20
: | oe , |
10. if val > 0 V(gate);
hae | | - (i) Find out the total no. of instances of each resource type.
. re : fis ; (ii) What is teh content of need matrix? :
12. } | at (iii) Is the system is in safe state? If yes, then what is safe sequence?
13. Ve(cs) { , | | ien (iv) If a request can be process P1 arries for (0, 4, 2, 0) can the request be
14. P(mutex); | | | granted immediately? (10.5)
15. val<val +1; | | pees \ Ans. 1. Need |
16. ifval=1 | A B ae Cc D
0 0 0 : |
17. V(gate);
0 7 3D :
18. V(mutex);
19°43 : ’ : 0
20. | , d0 . ae : 4 .
UNIT-III a, Aiea .
| | 2. Banker's Aigoriuum
Q.6. (a) What is deadlock? List four necessary conditions for the occurrence Step 1: ;
of deadlock. - Safety for process P,
Ans. In an operating system, a deadlock occurs when a process or thread enters a : ies
. Need, = (0, 0, 0, 0)
waiting state because a requested system resource is held by another waiting process,
Ifneed, < Available
which in turn is waiting for another resource held by another waiting process. Ifa process
, 0, 0, 0) < (1 ,5 ,2 0)] (tr ue)
is unable to change its state indefinitely because the resources requested by it are being if ((0
___used by another waiting process, then the system is said to be in a deadlock Process P, will execute.
e s t e r , O p e r a t i n g System
Sixth Sem LP. Uni . T e c h | - A k a sh Books
niver s i t y - [ B
22-2018 p r o e s e e o t h a
b l e = Av ai la bl e + A l location
Availa
= (1, 5, 2, 0) + (0,
0, 1, 2) vailable 0+,0Al0l)ocation
available ,= A12
= (2, 14,12 ) +(1,
= (1, 5, 3, 2)
= (3, 14: 12, 12)
Step 2: eat
er et
Safety for process P, pr
2 est from b e g r a n ted
gif s , C a n it
Sat = (0, 7, 5, 0) process P, for (0, 4,
2, 0) arr i v e
diately? :
< Avai ‘ | e available. So
ifneed, e q u e s t it w i l l t f r o m t h
l l o c a t e d p r o c e s s P ,
0) r s u b t r a c
r a 0;
owAfatvea lable comes (1, 1,
3, 2)]
if [(0, 1, 5. 0) ta
Process P, 2 must wait * step 1:
safety for process P,
Step 3:
Safety for process P,
Need, = (0,0, 0,0)
if need, < Available
Need, = (1, 0, 0, 2) 0, 0) < GL , 1, 0, 0D ) (t ru e)
ifneed, < Available
3 +f {(0, 0»
e.
0 , 2) < (1, 5 , 3 , 2 ) (tr u e) process Py will execut
if1(1, 0 , A v a i l a b l e + A llocation
| Availab l e —
r o c e s s P, wi ll e xec u te.
P 4,9)
ble + Allocation a (ks 1, 0, 0) + 0,9,
Available = Availa
5, 4) 3,
= (1,5, 3,2) +0, 3,
Step 2:
= (2, 8, 8, 6) Safety for process
P,
Step 4: |
P, Need, = (0, 7,5, 9)
Safety for process le
‘fneed, < Availab
need, = (0, 0, 2, 0) , 2))
e s£[(0, 7,9 Oy< (1, 1,1
If need, < Availabl
, 0 ) < (2, 8, 8, 6)] process P, must wait.
If [(0, 0, 2
. Step 3:
Process P, will execute
e = A v ail a ble + Al l oca t ion |
otra _ gafety for process P,
Availabl Need,= (1,0, 0,2)
_ (2, 8, 8, 6) + (0, 6, 3, 2) ae Se | if need, < Availabl
e
2/5 14/10, Beds ORO | |
2) ] ( t r ue)
, , 2) < (1 , 1, 1,
4 | sf[(1, 0,0
Step 5: ai cute. —
| tate P r o c e s s P s w i l l e x e
Safety for process P; | oe
i l a b l e + A l l o c a t i o n —
| tn FAR | Available = Ava
Need, = (0, 6, 4, 2) 4 0 , 3 , 5 % )
~(4 , 1 , 1 , 2 )
if need, < Available
6, 4, 2 ) . < ( 2 , 1 4 , 11 , 8) ! = (2, 4, 6,6)
if [(0, . }
| Step 4:
Process P, will execute. ;
Safety for process Py
| .
b le + Al l oca tion i
Available = Av a ila
| tas need, = (0, 0, 2, 9)
~ (2, 14, 11, 8) + (0, 0, 1, 4) If need, < Availa
ble ; Loe
=(2, 14,12, 12) 2 , 9 ) < ( 2 , 4 , 6 , 6)
If{( 0 , 0,
Step 6: ope
Process P, will execute: n
Safety for process P, e = A v a i l a b l e + A l l o c a t i o
need, = (0, 7, 5, 0)
Availabl
4, 6, 6) + 0 , 6 3, 2)
if need, < Available ~ (2 ,
£((0, 7,5, 0) < (2, 14, 12, 12))
=(2, 10, 9,8)
24-2018
Sixth Semester, Operating Syst
em
Step 5:
ae
afety for proce LP University_rp
ss P. ‘Tech, Akas
Need, = (0, 6, 4, The Schedul h Books
e using “F
2) 143, 86, 147
CEg? ;
if need, 0, 913
< Available The a
total seek d
ieters
if [(0, 6, 4, 2) < ( (ii) The schedule
2,10, 9, 8)] Using
Process P. will ex 143, 130, 86,
ecute. 913.
Available = Availab So the total
le + Allocation Seek
dist
(iii) The S
= (2, 10, 9, 8) 4 (0, 0, 1, cheduling u
4) sing “SCAN?
143, ;
913, 948 | 102
= (2, 10, 10, 12) 2, ‘<
Step 6:
Safety for p rocess Ps
need, = (0, 7, 5, 0) The total seek di
stance is 3319 cyli
if need, < Available (v) The schedule usin
nders
g “C. SCAN” is —
|
if [(0, 7,5, 0) <2, 10, 10, 12)] 143, 913, 948, 1022
, 1470, 1509, 1750
, 1174, 4999 3¢ 1
Process P, will execute. The total seek distan
ce is 9813 cylinders.
(vi) The schedule using “ eae
Available = Available + Allocat C-LOOK? is —
ion
43, 913, 948, 1022, 14
= (2, 10, 10, 12) + (1, 0, 0, 0) 70, 1509, 17150, 1774, 96
130
= (3, 10, 10, 12) The total seek distance is 33
63 cylinders. VE:
Safety Sequence = <P,, Ps, P,, P UNIT-IV
;, P,>
Hence the new system state is safe, so we can immediately grant the reque
st for Q.8. (a) Discuss all File allocation methods, ©)
process P,
1 ees Ans. The allocation methods define how the files are storedin the @
Q.7. Suppose a driver has 5000 cylinders, numbered 0 to 4999. The drive js | are three main disk space or file allocation methods. in the disk blocks. There
currently serving a request at cylinder 143 and the previous request was at | e Contiguous Allocation
cylinder 125. The queue of pending requests in FIFO order is-866, 1470, 913, 1774, e Linked Allocation
948, 1509, 1022, 1750, 130. . . e Indexed Allocation
Starting from current head position what is the total distance (in cylinders)
The main idea behind these methods is to provide:
that the disk arm moves to satisfy all pending requests for each of the following
e Efficient disk space utilization.
disk scheduling algorithms?
(i) FCFS (ii) SSTF (iii) Sean. e Fast access to the file blocks.
(iv) Look (v) C-Scan
(vi) C-Look All the three methods have their own advantages and disadvantages as discussed
(12.5)
Ans. below:
|
1. Contiguous Allocation |
2) | ple,
125 1509 1774
In this scheme, each file occupies a contiguous set of blocks onthe disk. For exam
O- 86 130 143 915 : 948 1022 i r e s b l o c k s a n d is g i v e n a b l o c k
b a s t h e s t a r t i n g l o c a t ion, spe a
1470 ¥ 1750y 4,999 ‘fa file requ n
s s i g n e d to t h e fi le w i l l be : b, b + 1 , b + 2 , . . . b + n-1. This means that given bs a
pice | a ired), we can
d r e s s a n d t h e l e n g t h of t h e fi le (i n t e r ms of blocks requ
block ad
ed by the file . | cs |
~ the blo cks occ upi
ory ent ry for a file wit h con tig uou s all oca tio n con tai ns
The direct
« Address of starting block
* Length of the allocated portion. arom the block 19 with length = 6 blocks.
The file ‘m ai l in th e fo ll ow in g fi gu rest ar ts fr on
Therefore, it occupies 19 , 20, 21, 22, 23, 24 blocks
26-2018
Sixth Semester, Operating System
Ad
h evaant nes . ,
LP. University-(B Tech|_Akash Books
the aan ithe Sequential and Direct Accesses are supported by this. For direct For files that are very large single index block 2018-27
(bak) Ss of'the kth block of the file which starts at block b can easily he obtai th ointers. ov< May not be able to hold all the
os
Mey P Following mechanisms can he use
° This is ext ] fi lb a Link sched Th d to resolve this-
allocation o f fiAletrbelmoeclkys fast since the number of seeks are minimal because 1. Limes Seheme: This scheme li
of CONtio, nks two or more index blocks together for holding
Disadvantages:
oe * This method suffers from both internal and external fragment
it inefficient in terms of memory utiliz ation. Thi.
atio
n. aa
. Increasing file size is difficult because it depends
on the availability of contj
memory at a particular instance.
| i
2. Linked List Allocation
In this scheme, each file is a linked list of disk blocks which need not be contigu,
Us, these poiit.
The disk blocks can be scattered anywhere on the disk. i the pointers contain the addresses of the
i ect blocks i.e
ei {node point to the dir ad
The directory entry contains a pointer to the starting and the ending file block. Each nat contain data of the file. The next few pointers point to indirect
blocks. Indirect blocks
block contains a pointer to the next block occupied by the file. s y be single indirect, double indirect or triple indirect. Single Indirect block is the bi
The file ‘jeep’ in following image shows how the blocks { does not contain the file data
are randomly distributeg disk eee data. Similarly double wikealide dea aa Gxt
he oT block (25) contains -1 indicating a null pointer and does
s ‘ . * 2 . dente
not point to any other
: tal

se disk address of the blocks that contain the address of the blocks containing
: © €

the fle
- Advantages:
ges: | ag Q.8- (b) Define the = “Free Space Management” techniques. | (6.5)
* This is very flexible in terms of file size. File size can be increased easily since the
, } Ans The system keeps tracks of the free disk blocks for allocating g space
spa to files
system does not have to look for a contiguous chunk of memory.
; : : . . | when they are created. Also, to reuse the space released from deleting the files, free
¢ This method does not suffer from external fragmentation. This makes it relatively ce management becomes crucial. The system maintain ea :
s a free space list which keeps
better in terms of memory utilization. | | 2 age of the disk blocks that are not allocated to some file or directory. The free space
| tra
Disadvantages: list can be im plemented mainly as: |
-® Because the file blocks are distributed randomly on the disk, a large number of |
1. Bitmap or Bit ve ct or :
,
seeks are needed to access every block individually. This makes linked allocation slower. t Ve c tor is ser ies or col lection of bits where each bit cor res ponds to
‘t map or Bi
¢ It does not support random or direct access. We can not directly access the blocks ke tw o va lu es : 0 and 1: 0 in di ca te s that th e bl oc k is allocated
a di cisa
ee ° wie bit can ta
of a file. A block k of a file can be accessed by traversing k blocks sequentially (sequential
‘dicates a free block.
access ) from the starting block of the file via block pointers. nae of disk blocks on the disk in Fig.1 (where green blocks are
The given ; insta
in nce
¢ Pointers required in the linked allocation incur some extra overhead. a by a bitmap of 16 bits as:0000111000000110.
a te d) ca n be re pr esente
3. Indexed Allocation | alloc
fan ett ~
In this scheme, a special block known as the Index block contains the pointers to all he
_ the blocks occupied by a file. Each file has its own index block. The ith entry in the index : ss A ee
block contains the disk address of the ith file block. The directory entry contains the
address of the index block as shown in the image:
Advantages:
¢ This supports direct access to the blocks occupied by the file and therefore provides
fast access to the file blocks.
_ © It overcomes the problem of external fragmentation.
Disadvantages: | |
¢ The pointer overhead for indexed allocation is greater than linked allocation.
e For very small files, say files that expand only 2-3 blocks, the indexed allocation
would keep one entire block (index block) for the pointers which is inefficient in terms of
memory utilization. However, in linked allocation we lose the space of only 1 pointer
per
block. | | |
28-2018 .
> Sixth Semester, Operating System
Advantages:
* Simple to understand.
* Finding the fi a
rst fr ee block is efficient. It re 1. Address o t would cont
8 bits) in a bitma quires scanning the Words a py f firg¢ free d 2018-99
p for a non-zero word. (A 2. Anumber np isk block
0-valued word has all bits 0). sre
block is then found by scanning The fire
for the first 1 bit in the non-zero For example
word. in Pigure-1_ t
The block number can he first entry
be calculated as: of th «
(number of bits per word) “(number
of 0-values words) + offset of bit first
the non-zero word . bit
hy
l. For the Fig.1: We scan the bitmap sequentially
| for the first non-zero Word
| Mm can
the first group of 8 bits (00001110) constitute a non-zero word {BM paren veh Tenning MS-DOS or MicrosofWata ne For example
deny
0. After the non-0 word is found, we loo since all bits are p of ey ner ovaten, and hidder attributes
k for the first 1 bit. This is the 5th bit Of
the thy
madows have eapabilities
zero word. So, offset = 5. *Read-only - Allows a file to be read, but
"| nothin
changed = canbe written to the file or
Therefore, the first free block number = 8*0+
5 = 5. *Archive - Tells Windows Backup to backup the file
2. Linked List: In this approach, the free disk blocks are linked
together je a free
block contains a pointer to the next free block. The block number of the very first digi
block is stored at a separate location on disk and is also cached in memory.
eer,

. Free list head \


pia
We Cet Ae REA

file pointer. Sunilarly, a write operation appe


the end of the newly written material i.e. th
the beginning. On some systems, a program may be able
to skip forward or backward n
records for some integer n. This scheme is known as sequenti
al access. Sequential
access is based on a tape model of a file.
2. Direct Access: Direct access is based on a disk model of a file. For direct access,
the file is viewed as a numbered sequence of block or records. A direct-access file allows
arbitrary blocks to be read or written. After block 18 has been read, block oT could be
next and then block 3. There are no restrictions on the order of reading and writing for a
direct access file. Direct access files are of great use for intermediate access to large
fo rm at io n. 7
amou nt s of in
The file operations must be modified
i are meter..
to include the b lock number as a para
In Figure-2, the free space list head points to Block 5 which points to Block 6, the
next free block and so on. The last free block would contain a null pointer indicating the It works like “read n’, where nis the block number rather than “read next”. Similarly, it
end of free list. writes with “write n” rather that “write next”.
A drawback of this method is the I/O required for free space list traversal. An alternative “approach retains “read next” and “write next”. tt adds = =
“position file to n” where n is the block number. Then we would issue
3. Grouping: This approach stores the address of the free blocks in the first free then “read next’ | 7 a.
sition to n” and
block. The first free block stores the address of some, say n free blocks. Out of these n. both sequ enti al and direc t acces s for files. So
- All operating systems supp ort
blocks, the first n-1 blocks are actually free and the last block contains the address of ac ce ss . Ot he rs al lo w on ly di re ct ac ce ss . So me ysstems
sy
systems allow only sequential file ch a
next free n blocks. : i a l or did i re ct wh en it
1 i
1ss cr ea crea ted. Su
require that a file should be define, d as se qu en ti al or
An advantage of this approach,is that the addresses of nly in a ma nn er def ine d a t the time ofi| ts declar
7 ation. ack |
a group of free disk blocks can
can be found easily.
Other access methods can be es} aes
. r — Acc
. he——
3. Ot Se
:
4. Counting: This approach stores the address of the ds generally involve the cons 3
number n of free contiguous disk blocks that
first free disk block and a access method. These additional metho
follow the first block.
30-2018 Sixth Semester, Operating System
4
"a

for a file. The index contains pointers to the various blocks. To find an entry ;
the index is searched first and the pointer is then
used to access the file direct] fi
the desired entry. : Yeoh,
With a large file, the index itself may become too large to be libraries May interce de
kept in memo pina | for th
© user
solution is to create an index for the index file. The prim Positioning Includ
ary index file Would ¢ “Oh skipping forward or re
es adjusting
mr e
pointers to secondary index files that would point to the actual data items. Verse ag Well as € locat;
posit;
| For example, IBM’s indexed sequential access method (ISAM)
uses a SMall ma.
index that points to disk blocks of a secondary index. The secondary
index blocks a,
to the actual file blocks. The file is kept sorted on a defined key.
We first make abi a
search of the master index to find a particular item: It pro May cause the
vides the block number ae
secondary index. This block is read in. Binary search is used again to fing
the ‘fe :
“st and validating
containing the desired record. Finally, this block is searched sequentia <S to indicate
lly. In this ee
any record can be located from its key by at most direct access reads. °Y,
Q.9. (b) What is the logical file system and physic
al file system? (4) deletions)
Ans. | Additional information
Physical file Logical file oyna May be ne
e A password << Ssary, for €Xample

1. Occupies the portion of memory. 1. Does not occupy any memory e A declarat
ion that Oth
er Processes
It contains the original data. space. Does not contain any data, jt is using the obj haring). Th;
May access th
€ Sam:
loads itself at run time as per th Pe e,
In contrast oe n cethat no other
a aa aratio may depend
). This Process on th © object while the opeming
defined access path. , may ac e mitent of the other process.
other processes intent (exclusive use). “ess the object regardless of the
2. A physical file contains one record 2. A logical file can contain up to 32°
format. record formats.
3. Can exist even without LF 3. Can’t exist without PF ry
4. If there is a logical file for a PF, the 4. Ifthereisa logical file for a PF, the
PF can’t be deleted until and unless LF can be deleted without deleting
we delete the LF. the PF. | |
5. CRTPF command is used to create 5. CRTLF command is used to
such creat such object. object. 2. The process may be prohibited from acc
essing the object (it may be only
accessible by a group or specific user),
Q.9. (c) Explain the purpose of create,open and close in file system. (2.5)
Ans. A file system API is an application programming interface through which a 3. The file system may be unable to create or update structures required to
utility or user program requests services of a file system. An operating system may coordinate activities among users.
provide abstractions for accessing different file systems transparently. 4. Inthe case of a new (or replacement) object, there may not be sufficient capacity

Some file system APIs may also include interfaces for maintenance operations, such on the media.
S$ creating or initializing a file system, verifying the file system for integrity, and Depending on the programming language, additional specifications in the open may
defragmentation. ; establish the modules to handle these conditions. Some libraries specify a library module
Each operating system includes the APIs needed for the file systems it supports. - to the file system permitting analysis should the opening program be unable to perform
mpt
Microsof. Windows has file system APIs for NTFS and several FAT file systems. Linux any meaningful action as a result of a failure. For example, ifthe failureison the atte
ilure and
systems can include APIs for ext2, ext3, ReiserFS, and Btrfs to name a few. to open the necessary input file, the only action may be to report the fa
me la ng ua ge s si mp ly re tu rn a co de in di ca ti ng the ty pe of fai lure whic
Write, read and position: Writing user data to a file system is provided for the program. So
ec ke d by the pro gra m, whi ch dec ide s wha t to rep ort and if it can
use directly by the user program or the run-time library. The run-time library for always must be ch
continue. | : 7 em
some programming languages may provide type conversion, formatting and
ear ejecting removabl e media and
Fe updati
wigng library
sacl
blocking. Some file systems provide identification of records by key and may include Close may cause dismountinorg ejecting removadle
re-writing an existing record, This operation is sometimes called PUT or PUTX (if , sres to indicate that the object
is no longer
some
|
file systems provid
and file eysten Sa sarcaes object. Additionally,
the record exists) | specification to the close references
32-2018 Sixth Semester, Operating System
specifying a disposition of the object which may indicate
the object is to be dig
and no longer be part of the fi
le system. Sipamilalar to the open, tb “ard.
something may go it must be “XPecteq thatSq
wrong.
1. The specification of the object may be incorrect.
2. There may not be sufficient cap
acity on the media to iad uit dat
da
a be; ‘ |
or to output a structure indicating that the object wa ma ge s Duf fer e,
s succe
3. A device error may oc
cur on the media waere th
buffered data, the completion structur e as aie tho chan ing
e or updating meta data re |
example last access time). | JECt (fo.
4. A specification to release the object may be in
sll using the object.
co ns is tent with other PTOCE gga,
Considerations for handling a failure are similar to those of the open.
Types of real time syst
ems based on timing con
1. Har, d real time Sys straints:
tem: T nis type of system
can never miss its deadline
.

the deadline may have disastrous Co . Missi


hard real time system de nseq uences. The usefulness of result produc : | :

ed bra
:

crease
in
ine crease
a s.eTardiness means how late a ;
real time syy stem compmp
leteies tes iti s task with respect
Example: Flight controller system
.
2. Soft real time system: T

Q.1. (b) Difference between Long Te


rm Scheduler and Short-Term
Scheduler.
(2)
Ans.
S.N. Long Term Scheduler Short Term Scheduler
1. | Itis a job scheduler It is a CPU scheduler
2. | Speed is lesser than short term Speed. is fastest among other
scheduler |
3. | It controls the degree of multi- It provides lesser control over degree of
programming multiprogramming
4. | Itis almost absent or minimal in It is also minimal in time sharing system
time sharing system ;
d. | It selects processes from pool and It selects those processes which are
loads them into memory for execution | ready to execute
Q.1. (c) What do you mean by process and thread? Differentiate both. (2)
Ans. (1) A program in execution is often referred as process. A thread is a subset(part)
of the process. ;
ts of mul tip le thr ead s. A thr ead is a sma lle st par t of the pro ces s
(2) A process consis
tha t can exe cut e con cur ren tly wit h oth er par ts( thr ead s) of the pro ces s.
ed as tas k. A th re ad is oft en re fe rr ed as li gh tw ei gh t
(3) A process is sometime referr
a e : 3
process.
es s spa ce. A th re ad us es the pr oc es s aa a space
(4) A process has its own ad dr
sh ar e it wi th the ot he r th re ad s of tha t pr oc ess.
and
2-~2019

(5) A thread can


conumunicate wi
using methods li th
ke wait(), notifyQ 3 Exclusion : Ifa 2019-3
process by using , noti Proceg. ) dip
inter-proc ess Process can yiut al ed to pr ocess 1S €xecuting
7 communication. commy execute in the in its critical sectio
(6) New thre Ncate Hd by critica} section. n, then no other
ads are easily cre ' 518 allow If no process is
ated. However “the,
cuplication of the pa the creation of ne
y Procegg,, oe ogres? he critical executing in the
critical section an
(7) Threads rent Process. F fF rgide t se ct ion, then only th d other processes
have cont; ol over tion can participate os e processes that are
not have control the other th; eads ; “Quin, in deciding which wi are not executing in
over the Sibling of the same Proceg | pr a der ake can not ll enter in the critical
Q. 1.
process, it has
co s, Dro be postponed indefinitely. section
(d) What is thr
ashing and ho
ntrol over Its
ch il d Procegge.® Cog,
po t a d th e s ee iting: A bou
Ans. Meaning w to encounter if it yo “ynded Wai th nd must exist on
of Thrashing: OCCurs? ei r critical sections the number of times
needs to Support p If the process do ae l af ter a process has that other processes
ages in active use, e s not have ny y e vo aan befor m a de a request to
Is called thrashing it wi l] q u i c k l y be ff (2) ] e th at re qu es t enter
. P a g e -fault. The high 3° a eal gectio ider is gr an ted.
pag; Pes it | 4s cf 9, (a) we t h e se t of processes P, to
In other words a l e e a g P. w i t h th j
e turnaround time e f ollowing oe
called thrashing. we can Say that when Page fault ratio de Activity ] a i Sia technique a n d a v e r a ge waiting time
for
uae
creaseg below w i t h t i m e q u a ‘a
Causes of Thr ] 5 Be. sched n t u m of 2 units. —
(1) IfCPU util
ashing: It re
sult in Severe
Performance
w e hiti g I g o b c e s s C P U B u r st Time
1
Arriv
Y introducing a
ization is too
low then We i P roblems
3
used. The CPU
new Process to
the System. A gl
ncrease the de
gree of Multipr
o
Ey 1
Scheduler sees obal] Page repla 6
0 multiprogramm th e decreasing CPU c e m e n t algo P o -
ine utilizatio 4
P;
(2) CPU utilizatio 5 :
n is Plotted a P,
gainst the degre o
(3) As the degree of e of P
multiprogramming :
(4) If the degree increases, ie ;
2
CPU utilization of multiprogramm
ing Is incr Ans.
drops Sharply. eased P id A. T.
(5) Soy at this | — a
decrease the de Point, to increas
e CPU utilizat Pp. 1
gree of multipro ion and to stop t Scere 9=0
gramming thrashing, We mu 6 - 2 = 4-2=2- < 2
Eliminate the | st |
Problem: Thras Fe 4
numberof Pages hing IS Caused . 4 - 2 5
required bya by under Ps 424> 0
can detect thra pr oc ess, forcing in i . § - 2=3-2=1-1= 6
shing by evalu it to continuo | P,
of multi Programmin ating the leve 8
g. It can be elimi l of CPU utilizati ¥ 2-2=0
nated by reducin Ps
Q.1. (e) What a ‘Time quantum
re the requirem
Problem ? ents of any s t to be find si>ze A. = T2AT? a
Ans. Critica] Sec | |
t Wha
accessed by onl io n Problem: Critical a e | AW.T?
y one Process section ; P| P3| Ps | Pol Pa
need to be Sync at a time. Critic P, |
hronized to a] Section cont SP Pa P| Ps} Pi} Pe
Maintain consi
stency of data
S. | la b] Ps a 41 0 4 d 17.19 20
vari Bip..2 4
fe
3
:
do { W.T. for
8
| Py 7
0+8+0 - a
11
|
entry section N
P;
T 7+4- 4
ge
=
1
>4+7+
6
| a7 % 3 9
Critical section a ae 0
P,—8+ 0 os

seinen = 94 wnt
ex section Total waiting tim
he
s

34 _ 6.8 unit
|
;

remainder section -. Average waiting en . es


ee

UMe=
* Ue

5
®

j
|
} while (TRUE); TA.T for B T coe 7 + 3 =
Rowe
10
"

="
stem
4—2019 Sixth Semester, Operating Sy Lp
Univers; a
Pi 042 2 2s ; Sity{B.Tech}-Aka
Shtal waiting shine = 84 ace page frame -, bat
No. of eT
Ans. 3 Ah"a as b 4,2.ce
Usdy _— .“
: 5A
So ATA. => a 10.8 Unit time. To be find — no. of page fault e

Q.2. (b) What is Virtual memory and how Overlay concept works, ©XDlain algo — optimal page replacement algo
short with example. , 2 1 2 4 i
Ans. Virtual memory is a memory management capability of an operating is, 4 4 4 = x x .
6 6| G {1 | 1} \ 1] \1]
(OS) that uses hardware and software to allow a computer to compensate for physi
PI (7 | , [S| |6| 6] le
memory shortages by temporarily transferring data from random access Memory (RA
) ‘ - 7| |7 | \7| t7| ra
to disk storage. Virtual address space is increased using active memory in RAY
inactive memory in hard disk drives (HDDs) to form contiguous addresses that hola 1 ra ry q X 3 ‘
both the application and its data. : ! 6 F | 1] {1
Virtual memory was developed at atime when physical memory becauge the 5 9 3 3 \4| \4\
installed RAM — was expensive. Computers have a finite amount of RAM, so memy 4 \ 2. 2
can run out, especially when multiple programs run a ee A system using So, total no. of page faults = 8. |
virtual memory uses a section of the hard drive to emula . With virtual memop, : ¢
a system can load larger programs or multiple programs running at the same tine A Eten fae ance apace of 4096 bytes. Main memory
allowing each one to operate as if it has infinite memory and without having to purchase ae .) what will beatna aka Meedlitictaaccaar cue partitioofn 16 byte each
more RAM. , Ce in the process? (c) How much internalGonuidccane. Pca ie
The main problem in Fixed partitioning is the size of a process has to be limited by ut the number of entries in general page table (e) How Pa @) rind
ere :¢ the page table is ses tearcecbedl cous Vieiaid many en Nees
the maximum size of the partition, which means a process can never be span over
another.In order to solve this problem, earlier people have used some solution whichis _ Ans. Logical address space = 4096 bytes
called as Overlays. | | = 22 bytes
| Then no. of bits is logical addr
The concept of overlays is that whenever a process is running it will not use the = 12 bits
complete program at the same time, it will use only some part of it.Then overlays concept
Main memory size = 512 bites = 2° bytes
says that whatever part you required, you load it an once the part is done, then you just
unload it, means just pull it back and get the new part you required and run it. Page size = 16 bytes
Formally, “The process of transferring a block of program code or other data into = 2* bytes
internal memory, replacing what is already stored”. | | Number of pages = Process size/Page size
Sometimes it happens that compare to the size of the biggest partition, the size of ye
the program will be even more, then, in that case, you should go with overlays. e = 28 = 256 page
So overlay is a technique to run a program that is bigger than the size of the physical Size of offset bits = 4 bits (because page size 2°)
memory by keeping only those instructions and data that are needed at any given ° = 256
no. of pages the process is divided
time.Divide the program into modules in such a way that not all modules need to be in No. of entries is page table =
the memory at the same time. | | No. Internal fragmentation
Q.3. (a) For a paged system, TLB hit ratio is 0.8. Let the RAM access time ‘t’ No. of pages = 2°
fr am es = 2° /2 * = 2 =3 2
be 100ns and the TLB access time ‘T’ be 50 ns. Calculate effective memory access No. of
time (with TLB). . of fr am es be co me no . of pa ges
In inverted page table, no
| (5)
Ans.
in in ve rt ed pa ge table =?
-. Entri e s
T(eff) = Hit ratio x (TLB access time + main memory access time) +
(1 — hit ratio) x (TLB access time (+) 2 x main memory time)
= 0.8 x (50 + 100) + (1 —.8) x (50 + 2 x 100)
= 0.8 x (150) + (.2) x (250) = 120.0 + 50.0 = 170.0 ns.
Q.3. (b) Calculate total number of page fault that will occur while processing
the page reference string given below:
4, 6, 7,1, 6, 7, 1, 2, 6, 2, 0, 3, 1, 4, 2 using Optimal page replacement policy;
when page frames are Three. (5)
END TERM EXAMINATION [JUNE 2019) | TYAB
Most OS also have an eta as .Tech|_Aka sh Books
SIXTH SEMESTER [B.TECH] mmands direct}
WO Canteoly toate; celatg
back door, wh;
if needed. In viens
2019-7
dita
OPERATING SYSTEMS [ETCS-304] peing accessed, an integer indicating a
to send
) System call ~%
Time :3 hrs. used for communicating oy coe
yoSAte
Note :- Attempt five questions in all including Q.No. 1. which MM. : 75 Caching involves keepin
is compulsory, Select
question from each unit : One data is normally stored.
Q.1. Answer the following short questions.
Q.1. (a) What does the CPU do when there are no programs to run
? (2.5)
Ans. If there are no tasks to run ona given CPU
in any of those classes gaya the
idle class, the CPU is regarded as idle. If the hardware doesn’
t make allowance for this
then the CPU will have to run useless instructions
until it is needed for real work, —
| Q.1. (b) Cana system detect that some of its processes are Star
ving? If yoy
answer “yes” explain how it can. If you answer “no”, explai
n how the System
deals with starvation problem?
(2.5)
Ans. Detection of starvation in effect requires future knowledge since no amount of
record-keeping statistics on processes can determine if it is making “progress”or not. directory sah This can be done, for example, by using the character
“” to indicate
the end of a subdirectory. Thus, for example, the
However, starvation can be prevented by “aging”a process. This means maintain name jim.java.F1 specifies that F1 is
ing a a file in subdirectory java which in turn is in the root
rollback count for each process, and including this as part of the cost factor in the selection directory jim. If file names were
limited to seven characters, then the above scheme could not
process for a victim for pre-emption/rollback. be utilized and thus, in
general, the answer is no. The next best approach in this situation would be to use a
Q.1. (c) In paging, why is it neccessary to add the page offset to the Starting
specific file as a symbol table (directory) to map arbitrarily long names (such as
address of the page frame to generate a physical address? (2.5) jim j ava.F 1) into shorter arbitrary names (such as XX00743), which are then used for
Ans. The offset is the distance (in bytes) relative to the start of the page. i.e., actual file access.
logical_address mod page_size. The bits for this portion of the logical address are not
Q.1. (g) How do placing index blocks near the data they reference, improve
translated (given power of two page size). The starting address of an n-bit page frame is (2.5)
a multiple of 2“n. Thus, the bit pattern of the frame’s starting address consists of the access time?
frame number followed by n 0’s. : Ans. Inodes allocated far from blocks — All inodes at beginning of disk, far from
|
Q.1. (d) What is hard page fault and soft page fault? data — Traversing file name paths, manipulatng files, directories requires going back
(2.5)
and forth from in nodes to data blocks.
Ans. Hard page faults occur when the page is not located in physical memory ora for the same file
memory-mapped file created by the process ... On the other hand, a soft page fault occur Data blocks allocated randomly in aging file systems — Blocks
s when FS is new As FS “ag es” and fill s, nee d to allocate into
when the page is resident elsewhere in memory allocated sequentially entially
eted — Problem: eet —s
blocks freed up when other files are del
Q.1. (e) Where are the following tasks implemented, in the logical I/O
layer, blo cks for ne w fil es be co me sca tte red 7 st = sang
the device driver, or both ? randomly placed — So,
, €2.5) in g of dis k, far fro m dat a. h a h aaa
All inodes at begi nn
(i) Checking access permissions ng back and fo
es, dir ect ori es req uir es goi
manipulating fil d a m e m o ry acce=ss
(ii) Scheduling the I/O operations
fault servic e i em . 25 ms an
Q.1. (h ) If th e av er ag e pa se
(iii) Checking if the requested information is in the cach th e ef fe ct iv e access 0
e Ca lc ul at e
time of 100ns. + memory access time.
Ans, User application access to a wide variety
of different devices is accomplished - a s fault service time
Ans tive access time = Page
through layering, and through encapsulating all of the device-specific code into
device
drivers, while application layers are presented with a common interface for all ( or ad lo ck to © ecu re? (2.5 )
45 for de
at rurn necessaryexco nd it+4:ions
least large general categories of.) devices. Q.1. (i) What are the fo amination 2018. (Page No. 20-2018)
Most devices can be characterized as either block I/O, character I/O, mem torQ. No. 6(a) End Term
Ans. Refe (2.5)
ory mapped
c a u s e s o f T h r a s h ing?
file access, or network sockets. A few devices are special, such as time-of-day
clock and . (j ) W h a t a r e t he
the system timer.
Q.1
82019 Sixth Semester, Operating System

UNIT -I
Q.2. (a) Compare and Constrast Network, Parallel and distributeg ope 2019-9
Ta ;
sysbems.,

Ans. A network operating system (NOS) is a computer operating system (Qg) i


is designed primarily to support workstations, personal computers and in thay
instances, older terminals that are connected on a local area network ( “ane, Otte
software behind a NOS allows multiple devices within a network to communicat
, Te | a” Sees — Page: for 28 byte page
share resources with each other. : © and (iv) Entire virtual ad
The composition of hardware that typically uses a NOS inclu dress:
des a numbe
personal computers, a printer, a server and file server with = Segment no. « page no
a local network that oat at . + offact
them together. The role of the NOS is to then provide basic network services =3+21+8=99,
and fea ™ Q.2. (c) Explain the di
that support multiple input requests simultaneously in a multiuser fference between a monoli at
environment. thic Operating system and
Due to earlier versions of basic operating systems not being design one based on micro-kernel archi . :
ed for network Ans. Monolithic Kernel
use, network operating systems emerged as a solution for single-user com
puters.
Parallel operating systems are the interface between The entire O.S. is placed inside the kernel
parallel computers (or * It runs as a single large process
computer systems) and the applications (parallel or not) that are executed on them
|
They translate the hardware’s capabilities into concepts usable by pro e As all the services are placed inside the kernel, they havea single addres
s space
gramming
languages. * It is bigger in size
: |
Great diversity marked the beginning of parallel architectures e It is easy to implement/code
and their operating
systems. This diversity has since been reduced to a sma ° Performance is high (As kernel can invoke any function directly as everythinisg
ll set of dominating
configurations: symmetric multiprocessors running commodity app
lications and placed in the kernel)
operating systems (UNIX and Windows NT) and multic s)
omputers running custom e Less Secure (If one service fails, entire system crashe
kernels and parallel applications. Additionally, there is some (mo |
stly experimental) icrokernel
work done towards the exploitation of the shared memory paradi
gm on top of networks | ba re mi ni mu m co de is pla ced ins ide the kernel (only basic memory
of workstations or personal computers. oe
r Pr oc es s Co mm un ic at io n cod e) nee
management an d In te
Distributed Operating System is a model where distributed applicatio called = oe ee
ns are ke rn el is br ok en do wn int o pr oc es se s
running on multiple computers linked by communications. A distributed ° Here the
operating e ser vic es) are se parated they
system is an extension of the network operating system that supports higher ° As services(Serve rs pr ov id
levels of
communication and integration of the machines oa the network. The Distribute spaces a 8
d Os
involves a collection of autonomous computer systems, capable of communicatin
g and * It is smaller in size
cooperating with each other through a LAN/ WAN.A Distributed Os provides a virtua ent/code
l e It is tough to implem pepe
machine abstraction to its users and wide sharing of resources like as computational
e is lo w (A s se rv er s are ”
® Performan c
capacity, I/O and files etc. |
servers [PC(Inter Process _time an d lowersgthe
ut performance
Q.2. (b) Ina system using paging and segmentation, the virtual address space
and thus increases acenes
consists of up to 8 segments where each segment can be upto 22° bytes long. The n if o n e s e r v i c e erash
(Eve
hardware pages each segment into 256 byte pages. How many bits in the virtual e More Secure
address specify the following: (4)
(i) Segment number
(ii) Page number |
(iii) Offset within page
(iv) Entire Virtual address
Ans. 3
(i) Segment no. = Virtual address space consist upto 8 segm tioning. 12.008
ents. faced by Fixed Part . during system
So, 8 = 28
Since 3 bits are needed to specify segment no.
Sixth Semester, Operating System
| lly RAM
1. Initia is empty and partitions are
.
to process’s nee d instead
ma de durin ‘ LP. Uni Versity. es
- of partition
i ing during syste g the run-ti * Tis eagy ty Merge adj ‘A
2. The size of partition will
m configure.
* Fast to allocsts cakes holes Tet Alena Books| MS
be equal to incoming process 19-11 a
3. The partition size varies accordin Dis
siadv anta ge. ory and q ®-alloeats
g to th teenie a: AN Memory
; e
e |
fragmentation can be avoided to ensu
re effici ation un; te

Paging is am “ntation LE
Advantages of Variable Partitio use in primary dram a data to, ' ‘and reading
ning ~ management

for
0 0
a computer’s
it & ad=
O8 (ove Main Memory, hig denen storage for
1. No Internal Fragmentatio
n: In vari In a memory management syster,rat ting system), 5 & tole
role; in memory _
is allocated strictly data from secondary stor
. age inb that takes ady
antage :
physical region of memory jag Called pages, all ane ung, the OS reads
NG; @ Single page 82 is; called
COMprise & frame. When
storage. This approach offers an shusiees ohysically continous paging is
until the memory is not empty. pecause it facilitates more effic BE over earlier
| 3. — Limitation on the size of the
process: In Fixed partitioning the pr
with the size greater than the size of the largest par ocess
tition could not be lowed and process Dut still suffer from internal
can not be divided as it is invalid in contiguous all fragmentation.
ocation technique. Here, In variable ° Paging is simple to implem
partitioning, the process size can’t be restricted sin sechinidle ent and assumed as
ce the partition size is decided 7
an efficient memory management
according to the process size. | * Due to equal size of the pages and
frames, swapping becomes very easy
Disadvantages of Variable Partitioning - e Page table requires extra memor |
be good fora system . having
1. Difficult Implementation: Implementing variable Partitioning is difficult as small RAM. SRA THEMOTY space, 80 may not
compared to Fixed Partitioning as it involves allocation of memory during run-time rather pageowin
Q.3. (b) Consider the foll g
reference string: (8)
than during system configure. | | 7, 2, 3, 1, 2, 5, 3, 4, 6, 1, T,1, 0, 5, 4, 6, 2,3, 0,1.
2. External Fragmentation: There will be external fragmentation inspite of Assuming demand paging with three frames, how many page faults would
absence of internal fragmentation. occur for the following replacement algorithms?
For example, suppose in above example- process P1(2MB) and process P3(1MB) (i) LRU replacement :
_ completed their execution. Hence two spaces are left i.e. 2MB and 1MB. Let’s suppose (ii) MFU replacement
srocess P5 of size 3MB comes. The empty space in memory cannot be allocated as no (iii) Optimal replacement
anning is allowed in contiguous allocation. The rule says that process must be 2, 3, 1, 25 ,3 ,4 ,6 ,7 ,7 , 1, 05 , 4, 82 3,051
Ans. String 7,
mtiguously present in main memory to get executed. Hence it results in External
No. of frames - 3
'Fragmentation. |
(i) LRU replacement
The buddy system is a memory allocation and management algorithm that
manages memory in power of two increments. Assume the memory size is 2U, suppose I mi
X
Xx

Tpol als
a size of S is required.
1 \7
¢ If 2U-1<§<=2U: Allocate the whole block 2
« Else: Recursively divide the block equally and test the condition at each time,
.
|8
when it satisfies, allocate the block and get out the loop.
' System also keep the record of all the unallocated blocks each and can merge these
different size blocks to make one big chunk,
: e
a
Advantage -
* Easy to implement a buddy system
* Allocates block of correct size
,sv

|
Sixth Semester, Operating System
; , ,

12-2019 LP. University_(p Techi-Akash p


5
(ii) MFU replacement : then CPU Utilization Percentage — an a 2019-13 * A S
Percentage wil — = @ aeeecs Gigs
CPU ideal
I It m § ‘ So
& cn
Xx X 1 Xx é | x
Xx
7 7 7 7 7 7 7 Zz = 100 w meal
7 7
2 2 2 5 3 4 6 3
2 basa1 Q.4. (b) Assume that two = 100 — g” _ |

3 1 1 1 1 1 1 t
jnitially set to 0. asks, Tl and T2 share the integer variables X, Y
x x 6 7 8 x 9 10 Xe ae
0 0 0 0 0 Task T1 execut
7 7 0 0 0 ! ,
X: = 0: es: Task T2 2)
7 Fee ;
Bh (Bde FO} eB] [Bt 3] Shiv abate 31 tae
i 1 i 5 4 403|4 4 4). [ap If X>0 then
white Y¥<2d
X; aX + Is > ¥-1- z
11 + III = 14 Page fault |
=> Y¥:=2;
’ PS
Y=1;
7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 7, 1, 0, 5, 4, 6, 2, 3, 0, 1 What are the possible values
) of< X and Y wh termina
(iii) Optimal Page Replacement Ans. Final value for
Men cee ny
x ae a, a
x | x x 1 X 2 xX 3 4 5
7 7 7 1 1 1 1 1 ry | 1 y: =
Q.4. (c) What resources are used
Bia Olas eae es She ee Bl Becks those when a process is created ?
when a thread is created? How do
they from
B( Sih. (Sl = (31) As) als el ne Ans. When a
) (2.5)
thread is created the threads does not
x x 6 x 7 8 9 10 x x require any new resources to
execute the thread shares the resources like
1 I 1 1 1 1 1 1 1 1 memory of the process to which they belong
to. The benefit of code sharing is that it allows an appl
5 5 5 5 4 6 2 8 iS 3 ication to have several different
threads of activity all within the same address space. Wherea if
7 7 0 0 0 0} 0 s a new process creation
0 0 0 is very heavyweight because it always requires new addres spa
s ce to be created and
even if they share the memory then the inter process communication is expensive when
> 10+ UI = 18 Page fault
compared to the communication between the threads. >

Q.3. (c) Why is Paging faster than Segmentation? (2.5)


Q.5. (a) Show how the Bakery algorithm satisfies the requirements of a
Ans. Paging is better and faster than Segmentation
mechanism to control access to a critical section. (6)
(1) Paging basically splits the Main Memory into equal sized portions for a program
Ans. Bakery. algorithm: The Bakery algorithm is one of the simplest known
implementation. Each program is allocated a certain number of virtual pages in the
Main Memory Unit that‘link to actual physical memory on the computer. solutions to the mutual exclusion problem for the general case of N process. The basic
(2) Segmentation takes pre-allocated spaces in the memory and places prog idea is that each non-thinking process has a variable that indicates the position of that
rams
into the slots that best fit the program size. Occasionally, this will cause smal process in a hypothetical queue of all the non-thinking processes. Each process in this
l segments
of unused memory on the machine. queue scans the variables of the other processes, and enters the critical section only
(3) Paging is better as it allows programs to use more memory upon determining that it is at the head of the queue.
than is actually
present, and it allows for switching between active pages to accomm
odate multitasking. But the resulting algorithm is still not easy to understand. So inthis note we first
city
ee addressing is an old approach that is extremely ine
fficient and rather look at a simplified version of the bakery algorithm, based a coarser grain of atomi
awkward, a than is allowed by the mutual exclusion problem. -
: |
Q.4. (a) Consider the I/O wait percentage, to the Crit ical Sec tio n Pro ble m must meet thre e conditions...
w, of a process is the perecntage of Solution
time the process waits for I/O complete
when executed ina monoprogrammed s is exe cut ing in its cri tic al sec tio n, no oth er pro cess
environment. On a system using roun 1. Mutual exclusion: If proces
d robin scheduling with n processes, is executing in its critical section :
nee ~ same I/O wait percentage, what all
percentage of the time will the CPU ec ut in g in :
its cri tic al se ct io n an d there exists some
3 2. Progress: If no process is ex e pr oc es se s - *
: (7) al sec tio ns, th en onl y th os
Ans. I/O wait percentage = rocesses that wish to enter their critic ci si on of which wi
pa rt ic ip at e in the de s g n
not exe: cut ing in the ir rem ain de r section caarn
no. of process = n : be postponed indefinite: ’
cannot
enter its critical section next, and this decision
WAR
m
, Operating Syste LP. University-[B.Tech|-Akash Books
Sixt , Semester 2019-15 —
14-2019 i who ente SJF |

e ag js ineaecritical rsection, Ati ca


e n decide nquickly ac ti ce ,
-
5
If no F l ss can ente the critical sectio io so in p pr , ot ers are put on the
4

| P, | Py Ps Ps P3
queue 0 4 3 -
ded wait ing: Ther e must exist a bound on the number of times that other 7 412 20
3. Boun ion s S after a process has made qa request Priority
- the ir
ir cricriti
tic al sec tio 1
processe 5 are allowed
to ente! the =
request is granted
ter its cri tic al sec tio n and before that
to enter
The wait is the time from when a process makes a request to enter its Critica] | P, | Py | Pa Pe Ps
ih
r e q u e s t is g r a n ted Pee sa te 20 LJ
section until that RR (quantum
= 2) |
In practic
c e s s e n t e r s its cr it ic al se ct io n, it d o e s no t ge t a n o ther turn
e, once a pro a turn (managed as a queue).
until a waiting process gets L
2
1 L P2
e re quir em en ts fo r cr it ic al sect ion problem Ps | P, | Ps | P3 P, | Fa} Pal Ps § Fs -
The th re 3 5 7 3 11 "15
- Suppose that Pi is in its critical section, and Pk(k!=i) has already chosen its 18 20
(ii) FCES
number[k], there are two cases:
1. Pk has already chosen its number when Pi does the last test before entering its TA = 2+3+11+15 +20
critical section. 5
In this case, if (number({iJ, 1) < (number[k],k) does not hold, since they cannot be
equal, so (number|i],i) > (aumber[k],k). Suppose this is true, then Pi cannot get into the
_ 5h 8 = 10.2
cirtical section before Pk does, and Pi will looping at the last while statement until the
condition does not hold, which is modifiedby Pk when it exits from its critical section, SIF _-1+347+12+20 .
Note that if Pk get a new number again, it must be larger than that of Pi’s. 5

2. Pk did not chose its number when Pi does the last test before entering its critica]
section. | awa
5
In this case, since Pk has chosen its number when P’ is in its critical section, Pk
must chose its number later than Pi. According to the algorithm, Pk can only get a bigger
ee 1+3+7+12+20
number than Pi, so (number[i],i) < number([k],k) holds. Priority = 5
Q.5. (b) Consider the following set of processes, with the length of the CPU
burst given in milliseconds: | (6.5)
= oF5 — acO.U.
Process | ‘Burst Time Priority
P Qi? | 2
42
2+3+53+20+
P, 1 a en = el
PR; 8 | 4
P, | 4 2 Rg
r 5 3 | 5
; le |
The process are assumed to have arrived in the order P,, P,, P,, P,, P; all at (iii) FCS ions
time 0. Answer the following questions using the following scheduling P,=90 P=}
algorithms: FCFS, SJE, Priority and RR(quantum=2)
P,=2 P,=0
({) Draw Gantt chart that illustrates the execution of these processes.
P,=3 Re
(ii) What is the turnaround time of each process for each of the scheduling
algorithm ? Ae | P,=il ¥,=0

(iii) What is the waiting time of each process for each of the scheduling P.=15 s

algorithm ? | : a a Priority 5 ‘
Ans. (i) FCFS pat °
P,=0
P,=2
3
re P,=49
Pp, = 12
, Op er at in g System
Semester
16-2019 Sixth p, = 16 ier |
IP. University-[B.Tech]|-Akash Books 2019-17
P,=3 P,=37 Q.6. (b) Why will da
P.=7 5 7
opeating systems than eadlock probably
it is today? Just Sty beseed
a moa iti problem in future
UNIT - Hil ae Ans. Sure, Deadlock probably be more critical
‘ ing current resource.
Q.6. (a) Consider a system with the followine © a allocatig,
state: P,, Py» Py Ps and three resource types: 4 p (6)
There are five processes: Pos : wienum: 2 Z Ang
C. For each process, the current allocation nee ein allocati,
mat ric es. The curren t available resource n
are given by Allocation and MAX are algorithms will be needed.
given by the Available vector. . - : pis
Answer the following questions using the Banker’s algorithm: s ~vasaieah dea a aaa Postponement? How does Indefinite
peceeneas ‘Aligoation z . — ; 2. ae Pos rtorm deadlock? How does Indefi
to deadlock? efinite ni Postponement similar
A B 5 ; ‘ 5 ; C Discuss the consequences of IP in the following types of Syste
Po 1 1
ms: (4.5)
2 ; - 5 0 (i) Batch processing
P. 2 1 | 2 , ; 5 (ii) Time sharing
P. 4 0 ; : : ; (iii) Real time
P4 0 2 : eS : onement may
Ans. Indefinite postp occur because of resource scheduling policies.
P,. 1 1 When resources are scheduled on a priority basis, it is possible for a given process
to
wait for a resource indefinitely as processes with higher priorities continue arriving. In
(i) What is the content of the Need matrix?
some systems, indefinite postponement is prevented by allowing a process’s priority to
(ii) Determine if this state is “safe” using Safety algorithm.
increase as it waits for a resource. This is called aging.
(iii) If a request from process P, arrives for (7,2,3) can the request be granted
immediately? In any system that keeps processes waiting while it makes resource allocation and
|
Ans. (i) Need matrix = Max , Allocation. Coe
is iti
ee ee ee a 1 Eenntodelay instefiniknly the echetolingel apracies
while other processes receive the system’s attention. This situation, called as indefinite
Process A B | Cc postponement or indefinite blocking or starvation.
P 3 2 1 ae Basis for Deadlock Starvation
P, 1 1 0 | YS Comparision ,
P; 5 0 l Basic Deadlock is where Starvation is where low priority
P, 7 3 3 : no process proceeds, and processes get blocked, and high
Pe. 10 1 1 get blocked. priority process proceeds.
; 7 : Arising condition | The occurrence of Mutual Enforcement of priorities,
(ii) P, cannot:run at first because need is more than available so— exclusion, Hold and wait, uncontrolled resource
first > ‘P,’, (1,1,0) < (2,1,0) available No preemption and management.
then available will be (4,2,2) Circular wait
Now > ‘P,’run simultaneously.
available 5,3,4 Other name Circular wait. Lifelock..
Now > P,’run Resources In deadlocked, requested In starvation, the requested
available 9,3,5 resources are blocked resources are continuously used
Now > P,’run are blocked by the other by high priority processes.
available 9,5,5 PRoceseds: es oe
oe is * 2 s cannot execute as demand/need is more than available. So system is not vrereutaa oe TA aad wail

(iii) Request of P, (7,2,3) cannot be granted immediately,


and einen reat “se
| allowing preemption.
‘ = | 5 A =
» ee;

18-2019 Sixth Semester, Operating System


IP. University-[B.Tech]-Akash Books 2019-19
Q.7. (a) Given the following track requests in the disk queue fok ws 1004
disk (0 - 99), compute for the Total Head Movement (THM) of the rea arte ) (iii) SCAN ooearee 8,99,74,52,75 (tends to zero)
Suppose movement is inward =
head:
UWrite
33, 72, 47, 8, 99, 74, 52, 75. : (6) Os) io res | 33 47 2.8 62% 75
Consider that the read/write head
is initially positioned at cylinder 99
to this, track location 99 was serviced. 63.
Show the total head mMOvement f lor
following scheduling algorithms: 47
or th >
(i) FCFS (ii) SSTF (iii) SCAN
33
(iv) C-SCAN |
(v) LOOK : | 5
Ans. (i) FCFS .
12 74 75 99 aie
Oat: 8 eS F925 368 72 74 75 99 Total head movement
= (63— 52) + (52— 47) + (4—7
33) + (8— 3
8) + (8
— 0) + (0 — 72) + (72 — 74)
+ (74— 75) + (75— 99)
=114+54+14+25+8+724+24+1+24= 162
(iv) C-SCAN
(Suppose movement is inward)

0 | 6 33 | 74 75 99
4? oe a a i

52

‘Total head movement | ac EEN:


| | |
= (63 — 33) + (83-72) + (72-47) + (47 — 8)+
(8— BO)t GO 74 ) + (7— 4 72
= 30+ 39 + 25 + 39 +914 25 + (22) +23 52) + (52-75)
a 2S oe Total head movement
= 294 | , = (63— 52) + (52-47) + (47-33) + (83 —8) + (3 0) + (0 — 99) + (99— 75) + (75— 74)
(ii) (SSTF) | Pde | | 7 + (74-72)
: a | |
os 8
TP ee
| = 11454+14+254+8+994244+1+2
nit
= |
s
(vy) LOOK (Suppose movement is inward) ee
63 74 | | :
| | el 755: pi Be 994
33 47 52 SS 72 74 15
s 33
en Oan
TT8 ) | |
Re

—@
99
Total head movement
= (63~ 72) + (72-74) + (7475) (75— 92) + (52-47) 72 74 75 99
+ (47— 33) + (83-8) + (8-99)
—.——_.—_______,

=5+24+1+234+5+14+425 491- 166 |


20-2019 Sixth Semester, Operating System
Total head movement LP. University-(
B Tech|-Akash
= (63 — 52) + (52-47) + (47-33) + (33 — 8) Books
+ (8— 72) + (72 —74) +(74~ 19) + (T6aby
= 1145414425
,
+644241494
= 146
Q.7. (b) Consider a disk having 8 surfaces,
each surface is havin
diameter of 16 cm and an inner diameter £ as Ute,
of 6 cm and the inner track SPace ig 9
mm. there are 32 sectors in each track. If the disk addr
ess for reading a byte =
& sector on any surface track of the dis
k is 27 bits. . i
(1) What is the sector size in bytes?
e °

(3

(ii) If the disk rotates at 3600 rpm, what is the effective data
transfer rate;
bytes/sec?
:;
Ans. Writable/readable area = 16—6 = 10 cm. physical block.
inner track space = 0.2 mm (ii) For indexed allocation direct access
. is also possible, but fir
100 indexing of that block through index block. So to ‘2? ur iirst we have to know
so total no. of tracks = om 500 tracks block access would be required
.
Q.8. (b) Discuss; various techni
ques for imi plementing File Access
(1) Sector size in bytes = 4 byte. Which techniqu e is appropriate for most of th Control.
e Systems? 4 a
(ii). Data transfer rate = no. of heads x capacity Ans. Access control is a security technique
of one track x no. of rotations/second. that can be used to regulate who or what
= 8 x 96 x 60 = 46,080 bytes/second. can view or use resources in a computing environment.
| |
Q.7. (c) What do you mean by Sector queuing? Describe There are two main types of access control: physical
SPTF algorithm, and logical. Physical access
control limits access to campuses, buildings, rooms and physical IT assets. Logi
cal
(3.5) access limits connections to computer networks, system files and data.
Ans. Sector queuing is an algorithm for scheduling fixed-head
devices. It is based The four main categories of access control are:
on the division of each track into fixed number of blocks called sectors. The disk a
in each request specifies the track and sector. Since seek time is zero for
ddress ¢ Mandatory access control —
fixed-head devices,
the main service time is latency time. For FCFS scheduling, assumi e Discretionary access control
ng that requ ests are
uniform distributed over sectors, the expected latency is one- e Role-based access control
half of a revolution.
e Rule-based access control
UNIT
- IV
' Access: control systems perform authorization identification, authentication,
Q.8. (a) Consider a file system on a disk that has both logical and
physical access approval, and accountability of entities through login credentials
sizes of 512 bytes. Assume that the information about each file is
already in including passwords, personal identification numbers (PINs), biometric scans, and
memory. For each of the three allocation strategies (contiguous, linked, and physical or electronic keys.
indexed), answer the following questions: (2.5)
(6) Q.8. (c) How operating system manages mounted file systems?
(i) How the logical to physical address mapping accomplished in this syst
em? Ans. Unix-like systems assign a device name to each device, but this is not how the
(For indexed allocation, also assume that a file is always less than 512 block ee
s files on that device are accessed. Instead, to gain access to files on another ao
long). Assume a pointer size of 1 byte. ae . . S
: operating system must first be informed where in the directory tree those
to sone ie
(ii) If we are currently at logical block 10 and want to access logical block 4, appear. This process is called mounting a file system. For example,
the file noe ae
how many physical blocks must be read from the disk? on a CD-ROM, one must tell the operating system “Take
. The ses = . Se
Ans. Let Z be the starting file address (block no.). ROM and make it appear under such-and-such ama
or ae cas
For contiguous allocation operating system is called the mount point — it sae
>
(1) Divide the logical address by 512 with X and Y the resulting quotient and remainder Se for removable media
neds is intendveed 9spe aN i =
respectively. Add X to Z to obtain the physcial block number, then Y is the displacement od See USB seas or floppy disks. It may be empty, or 1t may contal
into that block. 7 to ri es for mo un ti ng in di vi du al eee
subdir ec unting of file
) ma y au th or iz e th e mo
(11) In contiguous we can access any block directly so we can directly access block 4, ra ll y, on ly th e ad mi ni st ra to r (i.e. root user
Gene
the block must be read is ‘1’, |
systems.
Fr
22+~2019 Sixth Semester, Operating System
Just like a file needs to be opened, a file system needs to be mounted. Os n.
LP. University_(B ‘Tec
know — The location of the device (partition) to be mounted — The location h|~Akash Books
in thee to Once that test passes, it wi 2019-23
file structure where the file system is to be attached. OS does, — Verify ll check the file contents fo
that th “Urreny text scripts — or an ELF r a #! (Shebang) header — fo
has a valid file system — Add new file system to the mount point header — for the most r |
(/medi aly) e deviog common binary executable fo
rmat. It
Q.9. (a) Explain various file alloca \ 1) \
tion methods with their Pros ang
~
Ons,

Ans. Refer to Q.No. 8(a), End Term Examination 2018. (Page No.
25-2018) (6.5)
Q.9. (b) How does support for havi
ng file with mu]
the delection operation on a file system? tiple names ¢ commands to be issued to the operating sy
stem (similar to a batch file). With
°MPlicate introduction of CP/M the
Ans, (a microcomputer operating system), the
(3) type of files commonly me
associated with COM extension changed to
| Physical file Logical file >= later
that of executable files. This convention was
carried over to DOS. Even when complement
| ed by the more general EXE file
1. | Occupies the portion of memory. > : format for executables, the compact COM files rema
1./ Does ined viable and frequently used
| It contains the original data.
not occu a i) Se ae under DOS.
are, memory
A file system API is an application programming interface through which a utility
or user program requests services of a file system. An operating system may provide
2.|A physical file contains
one record abstractions for accessing different file systems transparently.
> 2. A logical file can
format. contain up to 32 Some file system APIs may also include interfaces for maintenance operations, such
record formats.
3.|Can exist even without
LF as creating or initializing a file system, verifying the file system for integrity,
: oe Can’t exist without PF
4. | If there is a logical file for and defragmentation. |
a PF the 4. If there isa logical
PF can’t be deleted until file tor a PF the Each operating system includes the APIs needed for the file erates i
and unless LF can be deleted wit
we delete the LF hout deleting supports. Microsoft Windows has file system APIs for NTFS and several FAT Sle
| the PF
5.| CRTPF command is used to create systems. Linuxsystems can include APIs for ext2, ext3, Reiser'S, and Btrfs toname a few.
5. | CRTLF command is used to |
such creat such object. Write, read and position
object.
Writing user data to a file system is provided for use directly by the user program
Different operating system keep tr >
ack of different file attributes includ
ing: r the run-time library. The run-time library for some eats ng os es
= |
| blocking. 8Some file ‘sy systems provi
3 vide type conversion, forma tting and
aan of records by key and may include re-writing an ore record
hed ena:
operation is sometimes called PUT or PUTX (if the at exists
aae aglow
Identifier - for example inode number Reading user data, sometimes called GET, may include
d file syst em, a speci fic key. As wi Wri -
_ Type - Text, executable, other binary reverse) or in the case of a keye
etc.
And many more like location, size, pro am.
tec tion, time and date etc. libraries may intercede fur Cleves: Bae o _ pa
Thisremaytiginclude
loc ati on of the pa s rec
System which did not originally have
multiple user file access permissions mu Positioning includes adjusting the
now be retrofitted if they are to share files st fo rw ar d or rev ers e as wel l as pos iti oni ng to the beginnin
ina network. Access to a file requires access skipping
to all the files along its path as well.- Open and close
In a cyclic directory structure user ma . 1: tly invoked upon the issuance
different access to the same file accessed y have : ‘ci ted or implicitly in pon bl
through different paths. Sometimes just The | open API Ari may be explicitly requesect. It may cause the m ounting a of reme ovable
knowledge of the existance of a file a certai the
ess on an obj
n name is a security concern. The file which of the first operation by a proc k . apand validating the met
is saved with multiple names arise a pr a co nn ec ti on to i ai
the gr id
hos t an 5 ind ica te tha t the
oblem with storage why some files are ) media, esta bl is hi ng obj ect is
replicated means contents with different e ob je ct . It updates sy
names. There is no problem in deletion of acce ss ib il it y of th
such type of files. Although there would be a pr
oblem if different files saved with single in use. t e m ob je ct include:
name and different extension. t oa fi le s y s
} u i r e m e n t s fo r r e q uesting access
Usual req i
ct o ry , m e d i a an d lo ca tion)
Q.9. (c) Why DOS and UNIX operating system
s recognize only executable w h i c h is to be ac ce ss e d (file, dire
1. The object th e op en (r ea ds , up dates,
files? | op er at ions to b be performe d afte r
(3) n t e n d e d ty pe of
Ans. There is the executable flag (Unix systems wil 2. The i
l refuse trying to interpret a file deletions) mation may be necessary, for example
as executable if the execute permission is not gra
nted; it applies even to root which "Additional info
ignores only read and write permissions, and treats any
of the execute bits as its own). * a password

_
;

zy

——————————
ti‘ S.w*;*;:S*Y ~~
24-2019
Sixth Semester, Operating System
proces* s8 jcdecilhaerat "5 other processes may access the same obj
ect whi]
In contrast 1€ Object (shariningg)). ThisThi may depend on the ii ntent of the “¢ ot
thh e *Pening
other ast , a dec lar
~‘aatration that no other process may access the
er processes intent (exclusive use).
ohi- €T prog
‘ object Pegardlag, itis, Q
These are r
equested via 4 progra
coordination a mming language library
ile idee: ©ng modu which m
in th
mm

les e process in addition to forwarding the re ay PYOvide


s - *,

quest to the
It mus
tbe ©€xpected that
7
something may go
wrong 8 Pp
a. The ob} . cessing of the Ope
Ject or intent may be i 1 7
y be improperly specified (the name
unac ceptable character or the intent . p nh.

is unrecognized). may include an


2. The process
may be prohibited from accessing the object (it |
bya STOUp. or specific user),
: ae = ee
re3.tic
dctivi : Ths e atm
filencnser
yst yste
uinmacemay y be unable
: e toto create or update structures requiri ed to coordinate )
i
on4.i In. the case of a ne
w (or replacement) object, there may not be sufficient capacity | |
asD ee on the programmin: g language, additi
Le :
onal specifications in the open ma |
ae ish the modules to handle these conditions. Some
libraries specify a library maaan
0 the file system permitting analysis should the
opening program be unable to serfana |
ae meaningful action as a result of a failure. For example, if the fai
lure is on the attempt
open the necessary input file, the only action may be to
report the failure and abort
= program. Some languages simply return a code indicating the type
of failure
which always must be checked by the program, which decides what
to report and if it
can continue. | 7 | |
Close may cause dismounting or ejecting removable media and updating library
_and file system structures to indicate that the object is no longer.in use. The minimal
specification to the close references the object. Additionally, some file systems provide
specifying a disposition of the object which may indicate the object is to be discarded
and no longer be part of the file system. Similar to the open, it must be expected that
something may go wrong.
1. The specification of the object may be incorrect.
2. There may not be sufficient capacity on the media to save any data being buffered
or to outputa structure indicating that the object was successfully updated.
. 8. A device error may occur on the media where the object is stored while writing
buffered data, the completion structure or updating meta data related to the object (for
example last access time). —
4. A ->ecification to release the object may be inconsistent with other processes still
using the object.
Considerations for handling a failure are similar to those of the open.

You might also like