os 24
Transcript of os 24
-
7/24/2019 os 24
1/25
UNIT-1
PART-A
1) What is virtual machine?
The application program view everything under them in the hierarchy as though thesystem programs were part of the machine itself. This layered approach is taken as
logical conclusion in the concept of a virtual machine.
2) What is an operating system?
An operating system is a program that manages the computer hardware. It act as an
intermediate between a users of a computer and the computer hardware. It controls
and coordinates the use of the hardware among the various application programs for
the various users.
3) i!!erentiate Tightly couple" systems an" loosely couple" systems?
Loosely coupled systems Tightly coupled systems Each processor has its own local
memory ommon memory is shared by many processors Each processor cancommunicate with other all through communication lines !o need of any special
communication lines
PART-#
1) istinguish $et%een the client-server an" peer-to-peer mo"els o! "istri$ute"
systems.
AN&W'R(
The client-server mo"elfirmly distinguishes the roles of the client and server.
"nder this model# the client re$uests services that are provided by the server.
%erver systems can be broadly categori&ed as compute servers and fileservers'
The compute-server systemprovides an interface to which a client can send a
re$uest to perform an action (for eample# read data)* in response# the server
eecutes the action and sends back results to the client. A server running a
database that responds to client re$uests for data is an eample of such a
system.
The !ile-server system provides a file+system interface where clients can
create# update# read# and delete files. An eample of such a system is a web
server that delivers files to clients running web browsers.
The peer-to-peer mo"eldoesn,t have such strict roles. In fact# all nodes in the
system are considered peers and thus may act as either clients or servers + or both. A
node may re$uest a service from another peer# or the node may in fact provide such a
service to other peers in the system.
1
-
7/24/2019 os 24
2/25
-etermining what services are available is accomplished in one of two general
ways'
hen a node /oins a network# it registers its service with a centrali&ed lookup
service on the network. Any node desiring a specific service first contacts this
centrali&ed lookup service to determine which node provides the service. The
remainder of the communication takes place between the client and the service
provider.
A peer acting as a client must first discover what node provides a desired
service by broadcasting a re$uest for the service to all other nodes in the network. The
node (or nodes) providing that service responds to the peer making the re$uest. To
support this approach# a discovery protocol must be provided that allows peers to
discover services provided by other peers in the network.
0or eample# let,s consider a system of nodes that share cooking recipes.
"nder the client+server model# all recipes are stored with the server. If a client wishes
to access a recipe# it must re$uest the recipe from the specified server. "sing the peer+to+peer model# a peer node could ask other peer nodes for the specified recipe. The
node (or perhaps nodes) with the re$uested recipe could provide it to the re$uesting
node. !otice how each peer may act as both a client (i.e. it may re$uest recipes) and
as a server (it may provide recipes.)
) '*plain $rie!ly a$out the services an" !unctions provi"e" $y the operating
system+AN&W'R(
An operating system provides an environment for the eecution of programs. It provides
certain servicesto programs and to the users of those programs.
User inter!ace+ Almost all operating systems have a user inter!ace ("I). This
interface can take several forms. 1ne is a comman"-line inter!ace ,.I)/ which uses
tet commands and a method for entering them (say# a program to allow entering and
editing of commands). Another is a $atch inter!ace/ in which commands and
directives to control those commands are entered into files# and those files are
eecuted. ost commonly a graphical user inter!ace ,0UI) is used.
Program e*ecution+ The system must be able to load a program into memory and to
run that program. The program must be able to end its eecution# either normally orabnormally (indicating error).
I2 operations+ A running program may re$uire I31# which may involve a file or an
I31 device. 0or specific devices# special functions may be desired.
ile-system manipulation+ The file system is of particular interest. 1bviously#
programs need to read and write files and directories. They also need to create and
delete them by name# search for a given file# and list file information.
ommunications+ There are many circumstances in which one process needs to
echange information with another process. ommunications may be implemented
via shared memory or through message passing# in which packets of information are
moved between processes by the operating system.
2
-
7/24/2019 os 24
3/25
'rror "etection+ The operating system needs to be constantly aware of possible
errors. Errors may occur in the 4" and memory hardware (such as a memory error
or a power failure)# in I31 devices (such as a parity error on tape# a connection failure
on a network# or lack of paper in the printer)# and in the user program.
UNTI2N&(
Resource allocation+ hen there are multiple users or multiple /obs running at the
same time# resources must be allocated to each of them. any different types of
resources are managed by the operating system. %ome (such as 4" cycles# main
memory# and file storage) may have special allocation code# whereas others (such as
I31 devices) may have much more general re$uest and release code.
Accounting+ e want to keep track of which users use how much and what kinds of
computer resources. This record keeping may be used for accounting (so that users
can be billed) or simply for accumulating usage statistics.
Protection+ 4rotection involves ensuring that all access to system resources iscontrolled. %ecurity of the system from outsiders is also important. %uch security
starts with re$uiring each user to authenticate himself or herself to the system# usually
by means of a password# to gain access to system resources.
3) '*plain $rie!ly system calls an" their types+
AN&W'R(
&ystem callsprovide an interface to the services made available by an operating system.
Application developers often do not have direct access to the system calls# but can access
them through an application programming interface (A4I). The functions that are included in
the A4I invoke the actual system calls. 5y using the A4I# certain benefits can be gained'
4ortability' as long a system supports an A4I# any program using that A4I can
compile and run.
Ease of "se' using the A4I can be significantly easier then using the actual system
call.
&ystem all Parameters(
Three general methods eist for passing parameters to the 1%'
6. 4arameters can be passed in registers.
3
-
7/24/2019 os 24
4/25
2. hen there are more parameters than registers# parameters can be stored in a block
and the block address can be passed as a parameter to a register.
7. 4arameters can also be pushed on or popped off the stack by the operating system.
Types o! &ystem calls(
There are 8 different categories of system calls' process control# file manipulation# device
manipulation# information maintenance and communication.
Process ontrol( A running program needs to be able to stop eecution either
normally or abnormally. hen eecution is stopped abnormally# often a dump of
memory is taken and can be eamined with a debugger.
ile 4anagement( %ome common system calls are create# delete# read# write# repositi
on# or close. Also# there is a need to determine the file attributes 9 get and set file
attribute. any times the 1% provides an A4I to make these system calls.
evice 4anagement( 4rocess usually re$uire several resources to eecute# if these
resources are available# they will be granted and control returned to the user process.
These resources are also thought of as devices. %ome are physical# such as a video
card# and others are abstract# such as a file.
"ser programs re$uest the device# and when finished they release the device. %imilar
to files# we can read# write# and reposition the device.
In!ormation 4anagement( %ome system calls eist purely for transferring
information between the user program and the operating system. An eample of this
is time# or date. The 1% also keeps information about all its processes and provides
system calls to report this information. ommunication( There are two models of inter process communication# the
message+passing model and the shared memory model.
essage+passing uses a common mailbo to pass messages between processes.
%hared memory use certain system calls to create and gain access to create and
gain access to regions of memory owned by other processes. The two processes
echange information by reading and writing in the shared data.
5) Defne the essential properties o the ollowing types o operatingsystem:
4
-
7/24/2019 os 24
5/25
(i) Batch(ii) Real Time(iii) Time sharing(i) !l"stere#
#AT6(
:obs with similar needs are batched together and run through the computer as a group
by an operator or automatic /ob se$uencer. 4erformance is increased by attempting to keep
4" and I31 devices busy at all times through buffering# off+line operation# spooling# and
multi+programming. 5atch is good for eecuting large /obs that need little interaction* it can
be submitted and picked up later.
Real Time(
1ften used in a dedicated application# this system reads information from sensors and must
respond within a fied amount of time to ensure correct performance .
Time sharing( This systems uses 4" scheduling and multiprogramming to provide
economical interactive use of a system. The 4" switches rapidly from one user to another.
Instead of having a /ob defined by spooled card images# each program reads its net controlcard from the terminal# and output is normally printed immediately to the screen.
$
-
7/24/2019 os 24
6/25
lustere"(A clustered system combines multiple computers into a single system to perform
computational task distributed across the cluster.
i. ;andheld' A small computer system that performs simple tasks such as cal
endars# email# and web browsing. ;andheld systems differ from traditional
desktop systems with smaller memory and display screens and slower processors.
UNIT-5
PART-A1) What is the "i!!erence $et%een logical an" physical a""resses?
An address generated by the 4" is commonly referred to as a logical address# whereas an
address seen by the memory unit is commonly referred to as physical address.
2) What is e*ternal !ragmentation?
Eternal fragmentation eists when enough total memory space eists to satisfy a re$uest# butit is not contiguous* storage is fragmented into a large number of small holes.
7)What is the use o! vali"-invali" $its in paging?
hen the bit is set to valid# this value indicates that the associated page is in the process,s
logical address space# and is thus a legal page. If the bit is said to invalid# this value indicates
that the page is not in the process,s logical address space. "sing the valid+invalid bit traps
illegal addresses.
PART-#
1) iscuss in "etail the paging concept?
Ans%er(
Logical address space of a process can be non contiguous* process is
allocated physical memory whenever the latter is available.
-ivide physical memory into fied+si&ed blocks called !rames (si&e is
power of 2# between 862 bytes and eep
track of all free frames.
To run a program of si&e npages# need to find n free frames and load
program
%et up a page table to translate logical to physical addresses
A""ress Translation &cheme
Address generated by 4" is divided into
%
-
7/24/2019 os 24
7/25
Page num$er ,p)9 used as an inde into apage table which contains base
address of each page in physical memory
Page o!!set ,")9 combined with base address to define the physical memory
address that is sent to the memory unit0or given logical address space 2mand page si&e 2n
Paging 6ar"%are
Paging Model of Logical and Physical Memory
&
-
7/24/2019 os 24
8/25
Eample of the page table'
onsider the memory using a page si&e of ? bytes and a physical memory of 72
bytes.
3-$yte memory an" 5-$yte pages
Free Frames:
'
-
7/24/2019 os 24
9/25
hen a process arrives in the system to be eecuted# its si&e is epressed
in pages.
Each page of the process needs one frame. Thus if the process re$uires n
pages at least n frames must be available.
The first page of the is loaded into any one of the frame and frame
number is put in the table for this process.
The net page is allocated into another frame and its frame number is put
into the page table# and so on.
Implementation of page table'
4age table is kept in main memory
Page-ta$le $ase register ,PT#R)points to the page table
Page-ta$le length register ,PR.R) indicates si&e of the page table
In this scheme every data3instruction access re$uires two memoryaccesses. 1ne for the page table and one for the data3instruction.
The two memory access problem can be solved by the use of a special
fast+lookup hardware cache called associative memory or translation
loo7-asi"e $u!!ers ,T.#s)
%ome TL5s store a""ress-space i"enti!iers ,A&Is) in each TL5 entry
9 uni$uely identifies each process to provide address+space protection for
that processAssociative 4emory
Associative memory 9 parallel search
-
7/24/2019 os 24
10/25
Address translation (p# d)
If p is in associative register# get frame @ out
1therwise get frame @ from page table in memory
Paging 6ar"%are %ith T.#
'!!ective Access Time
Associative Lookup e time unit
Assume memory cycle time is 6 microsecond;it ratio 9 percentage of times that a page number is found in the associative
registers* ratio related to number of associative registers
;it ratio an '!!ective Access Time (EAT)
EAT (6 B e) a B (2 B e)(6 9 a)
2 B e 9 a.
,) What is eman" Paging iscuss?
A demand paging is similar to a paging system with swapping. hen we
want to eecute a process# we swap it into memory. Cather than swapping the
entire process into memory.
hen a process is to be swapped in# the pager guesses which pages will
be used before the process is swapped out again Instead of swapping in a whole
process# the pager brings only those necessary pages into memory. Thus# it
avoids reading into memory pages that will not be used in anyway# decreasing
the swap time and the amount of physical memory needed.
1
-
7/24/2019 os 24
11/25
;ardware support is re$uired to distinguish between those pages that are
in memory and those pages that are on the disk using the valid+invalid bit
scheme. here valid and invalid pages can be checked checking the bit and
marking a page will have no effect if the process never attempts to access the
pages. hile the process eecutes and accesses pages that are memory
resident# eecution proceeds normally.
0ig. Transfer of a paged memory to continuous disk space
Access to a page marked invalid causes a page+fault trap. This trap is the
result of the operating systemDs failure to bring the desired page into memory.
5ut page fault can be handled as following
11
-
7/24/2019 os 24
12/25
%teps in handling a page fault
6. e check an internal table for this process to determine whether the referencewas a valid or invalid memory access.
2. If the reference was invalid# we terminate the process. If .it was valid# but we
have not yet brought in that page# we now page in the latter.
7. e find a free frame.
?. e schedule a disk operation to read the desired page into the newly
allocated frame.
8. hen the disk read is complete# we modify the internal table kept with the
process and the page table to indicate that the page is now in memory.
. e restart the instruction that was interrupted by the illegal address trap. The
process can now access the page as though it had always been memory.
Therefore# the operating system reads the desired page into memory and restarts
the process as though the page had always been in memory.
12
-
7/24/2019 os 24
13/25
The page replacement is used to make the frame free if they are not in used. If
no frame is free then other process is called in.
A"vantages o! eman" Paging(
6. Large virtual memory.
2. ore efficient use of memory.
7. "nconstrained multiprogramming. There is no limit on degree of
multiprogramming.
isa"vantages o! eman" Paging(
?. !umber of tables and amount of processor over head for handling page
interrupts are greater than in the case of the simple paged managementtechni$ues.
8. -ue to the lack of an eplicit constraints on a /obs address space si&e.
,3) '*plain in "etail a$out segmentation %ith paging+
%egmentation is a memory+management scheme that supports this user
view of memory. A logical address space is a collection of segments.
Each segment has a name and a length.
The addresses specify both the segment name and the offset within the
segment.
The user therefore specifies each address by two $uantities' a segment
name and an offset.
0or simplicity of implementation# segments are numbered and are referred to by
a segment number# rather than by a segment name. Thus# a logical address
consists of a two tuple:
F segment+number# offset G.
!ormally# the user program is compiled# and the compiler automatically
constructs segments reflecting the input program.
A compiler might create separate segments for the following'
6. The code
2. Hlobal variables
7. The heap# from which memory is allocated
?. The stacks used# by each thread
13
-
7/24/2019 os 24
14/25
8. The standard library
The user can now refer to ob/ects in the program by a two+dimensional address#
the actual physical memory is still# of course# a one+dimensional se$uence of
bytes. Thus# we must define an implementation to map two dimensional user
defined addresses into one+dimensional physical addresses.
This mapping is effected by a segment table. Each entry in the segment
table has asegment base and asegment limit.
The segment base contains the starting physical address where the
segment resides in memory# whereas the segment limit specifies the
length of the segment.
14
-
7/24/2019 os 24
15/25
A logical address consists of two parts' a segment number#s, and an
offset into that segment# d.
The segment number is used as an inde to the segment table. The offset
d of the logical address must be between and the segment limit.
If it is not# we trap to the operating system (logical addressing attempt
beyond# end of segment). hen an offset is legal# it is added to the segment base to produce the
address in physical memory of the desired byte.
'*ample(
e have five segments numbered from through ?. The segments are
stored in physical memory as shown.
The segment table has a separate entry for each segment# giving the
beginning address of the segment in physical memory (or base) and the
length of that segment (or limit).
1$
-
7/24/2019 os 24
16/25
,5) '*plain in "etail the structure o! the page ta$le
The most common techni$ues for structuring the page table.
;ierarchical 4aging
;ashed 4age Tables
Inverted 4age Tables
6ierarchical Paging
ost modern computer systems support a large logical address space (272
to 2?). In such an environment# the page table itself becomes ecessively large.
0or eample# consider a system with a 72+bit logical address space.
If the page si&e in such a system is ? >5 (262
)# then a page table mayconsist of up to 6 million entries (2723262).
1ne simple solution to this problem is to divide the page table into
smaller pieces. A simple techni$ue is a two+level page table.
1%
-
7/24/2019 os 24
17/25
T%o-.evel Paging '*ample
A logical address (on 72+bit machine with 6> page si&e) is divided into'
a page number consisting of 22 bits
a page offset consisting of 6 bits
%ince the page table is paged# the page number is further divided into'
a 62+bit page number
a 6+bit page offset
Thus# a logical address is as follows' wherepi is an inde into the outer
page table# andp2 is the displacement within the page of the outer page
table
1&
-
7/24/2019 os 24
18/25
Address-Translation Scheme
6ashe" Page Ta$les
ommon in address spaces G 72 bits
The virtual page number is hashed into a page table
This page table contains a chain of elements hashing to the same location
Jirtual page numbers are compared in this chain searching for a match
If a match is found# the corresponding physical frame is etracted
1'
-
7/24/2019 os 24
19/25
Inverte" Page Ta$le
1ne entry for each real page of memory
Entry consists of the virtual address of the page stored in that real
memory location# with information about the process that owns that page
-ecreases memory needed to store each page table# but increases time
needed to search the table when a page reference occurs
"se hash table to limit the search to one K or at most a few K page+table
entries
1
-
7/24/2019 os 24
20/25
UNIT-8
PART-A
1) What is a Resource-Allocation 0raph?
-eadlocks can be described more precisely in terms of a directed graph calleda system resource allocation graph. This graph consists of a set of vertices J and a set
of edges E. The set of vertices J is partitioned into two different types of nodes* 4 the
set consisting of all active processes in the system and C the set consisting of all
resource types in the system.
) What are the metho"s !or 6an"ling ea"loc7s?
The deadlock problem can be dealt with in one of the three ways'
"se a protocol to prevent or avoid deadlocks# ensuring that the system will
never enter a deadlock state.
Allow the system to enter the deadlock state# detect it and then recover.
Ignore the problem all together# and pretend that deadlocks never occur in the
system.
3) What are a &a!e &tate an" an Unsa!e &tate?
A state is safe if the system can allocate resources to each process in some order and
still avoid a deadlock. A system is in safe state only if there eists a safe se$uence. A
se$uence of processes F46#42#.4nG is a safe se$uence for the current allocation state if# for
each 4i# the resource that 4i can still re$uest can be satisfied by the current available resource
plus the resource held by all the 4/# with /Fi. if no such se$uence eists# then the system state
is said to be unsafe.
PART-#
1) '*plain a$out "ea"loc7 prevention $rie!ly?
,or)
6o% can %e prevent the occurrence o! "ea"loc7s? iscuss in $rie!+
AN&W'R(
0or a deadlock occurrence# each of the four necessary conditions must hold. 5y
ensuring that at least one of these conditions cannot hold# we can prevent the occurrence of a
deadlock.
5y eamining each of the four necessary conditions'6) utual Eclusion
2) ;old and ait
7) !o 4reemption
?) ircular ait
4utual '*clusion(
The mutual+eclusion condition must hold for non+sharable resources. 0or eample# a
printer cannot be simultaneously shared by several processes. %harable resources# in contrast#
do not re$uire mutually eclusive access and thus cannot be involved in a deadlock. Cead+
only files are a good eample of a sharable resource. If several processes attempt to open aread+only file at the same time# they can be granted simultaneous access to the file. A process
2
-
7/24/2019 os 24
21/25
never needs to wait for a sharable resource. In general# however# we cannot prevent deadlocks
by denying the mutual+eclusion condition.
6ol" an" Wait(
To ensure that the hold+and+wait condition never occurs in the system# we must
guarantee that# whenever a process re$uests a resource# it does not hold any other resources.eans protocol allows a process to re$uest resources only when it has none.
Another protocol is that can be used re$uires each process to re$uest and be allocated
all its resources before it begins eecution.
The difference between these two protocols# we consider a process that copies data
from a -J- drive to a file on disk# sorts the file# and then prints the results to a printer. If all
resources must be re$uested at the beginning of the process# then the process must initially
re$uest the -J- drive#
disk file# and printer. It will hold the printer for its entire eecution# even though it needs the
printer only at the end.
The second method allows the process to re$uest initially only the -J- drive and
disk file. It copies from the -J- drive to the disk and then releases both the -J- drive andthe disk file. The process must then again re$uest the disk file and the printer. After copying
the disk file to the printer# it releases these two resources and terminates.
5oth protocols have some disadvantages'
6) Cesource utili&ation may be low# since resources may be allocated but unused for a long
period.
2) %tarvation' A process that needs several resources may have to wait indefinitely# because
at least one of the resources that it needs is always allocated to some other process.
No Preemption(
If a process is holding some resources and re$uests another resource that cannot be
immediately allocated to it (that is# the process must wait)# then all resources currently being
held are preempted. In other words# these resources are implicitly released. The preempted
resources are added to the list of resources for which the process is waiting.
Alternatively# if a process re$uests some resources# we first check whether they are
available. If they are# we allocate them. If they are not# we check whether they are allocated
to some other process that is waiting for additional resources. If so# we preempt the desired
resources from the waiting process and allocate them to the re$uesting process. If the
resources are neither available
nor held by a waiting process# the re$uesting process must wait. hile it is waiting# some of
its resources may be preempted# but only if another process re$uests them. A process can berestarted only when it is allocated the new resources it is re$uesting and recovers any
resources that were pre+empted while it was waiting.
ircular Wait(
Each process re$uests resources in an increasing order of enumeration. To illustrate#
we letR {R0, Ri, ...#Rm} be the set of resource types. e assign to each resource type a
uni$ue integer number# which# allows us to compare two resources and to determine whether
one precedes another in our ordering. 0ormally# we define a one+to+one function 0'R > N,
whereN is the set of natural numbers. 0or eample# if the set of resource typesR includes
tape drives# disk drives# and printers# then the function 0 might be defined as follows'0(tape drive) 6
21
-
7/24/2019 os 24
22/25
0(disk drive)8
0 (printer) 62
Each process can re$uest resources only in an increasing order of enumeration. That is# a
process can initially re$uest any number of instances of a resource typeKsay# C. After that#
the process can re$uest instances of resource type C* if and only if 0(C*) G 0(C#).
) '*plain in "etail the $an7er9s algorithm?
,or)
AN&W'R
0or avoiding deadlocks is to re$uire additional information about how resources are to
be re$uested. The various algorithms that use this approach differ in the amount and type of
information re$uired. The simplest and most useful model re$uires that each process declare
the maimum number of resources of each type that it may need. Hiven this a priori#
information# it is possible to construct an algorithm that ensures that the system will never
enter a deadlocked state. %uch an algorithm defines the deadlock+avoidance approach.hen# a new process enters the system# it must declare the maimum number of
instances of each resource type that it may need. This number may not eceed the total
number of resources in the system. hen a user re$uests a set of resources# the system must
determine whether the allocation of these resources will leave the system in a safe state. If it
will# the resources are allocated* otherwise# the process must wait until some other process
releases enough resources.
%everal data structures must be maintained to implement the bankerDs algorithm.
Availa$le+ A vector of length m indicates the number of available resources of each
type. If AvailableM/N e$uals k# there are k instances of resource type C/ available.
4a*+ An n m matri defines the maimum demand of each process. If aMiN
M/Ne$uals k# then process 4i may re$uest at most k instances of resource type C/.
Allocation. An n m matri defines the number of resources of each type currently
allocated to each process. If AllocationMiNM/N e$uals k# then process 4i is currently
allocated k instances of resource type C/.
Nee"+ An n m matri indicates the remaining resource need of each process. If
!eedMiNM/N e$uals k# then process 4i may need k more instances of resource type C/ to
complete its task. !ote that !eedMiNM/N e$uals aMiNM/N+ AllocationMiNM/N.
22
-
7/24/2019 os 24
23/25
&a!ety algorithm
The algorithm for finding out whether or not a system is in a safe state.
6) Let ork and 0inish be vectors of length in and n# respectively. Initiali&e
ork Available and 0inishMiN false for i#6#.. n+6.
2. 0ind an i such that both
a. 0inishMiN falseb. !eediF ork
If no such 3 eists# go to step ?.
7. ork ork B Allocation#
0inishMiN true
Ho to step 2.
?. If 0inishMiN true for all. I# then the system is in a safe state.
Resource-Re:uest Algorithm
The algorithm which determines if re$uests can be safely granted.
Let Ce$uestibe the re$uest vector for process 4i If Ce$uestiM /N k# then process 4iwants k instances of resource type C/ hen a re$uest for resources is made by process 4i the
following actions are taken'
6. If Ce$uestiF!eedi go to step 2. 1therwise# raise an error condition# since the process
has eceeded its maimum claim.
2. If Ce$uestiF Available# go to step 7. 1therwise# 4i must wait# since the resources are
not available.
7. ;ave the system pretend to have allocated the re$uested resources to process 4 iby
modifying the state as follows'
Available Available 9 Ce$uesti*
Allocationi AllocationiB Ce$uesti*
!eedi !ecdi9 Ce$uesti*
If the resulting resource+allocation state is safe# the transaction is completed# and process 4 iis
allocated its resources.
';A4P.'(
onsider a system with five processes 4through 4? and three resource types A# 5#
and . Cesource type A has 6 instances# resource type 5 has 8 instances# and resource type
has O instances.
proce
sses
ALL1A
TI1!
A
P
AJAILA
5LE
A 5 A 5
A 5
4 6 O 8
7
7 7 2
46 2 7 2
2
42 7 2 =
2
47 2 6 6 2 2
2
4? 2 ? 7
7
23
-
7/24/2019 os 24
24/25
!ow we have to calculate the need. !eedMiNM/N aMiNM/N+AllocationMiNM/N
4rocesse
s
!eed
A 5
4 O ? 746 6 2 2
42
47 6 6
4? ? 7 6
1ur work available# so work 7 7 2
!ow check for need weather !eedFwork then p not satisfied then go for p6# which satisfies
the need then p6 will starts its eecution. After p6 completes its eecution it releases its
allocated resources then availability is 8 7 2.
Then again check for need of resources of other processes then p 7 satisfies after that itreleases its resources then availability is O ? 7. Then net p#p2# p?.%o the safe se$uence is
Fp6# p7# p# p2# p?G.
3) 6o% to recover !rom "ea"loc7? '*plain
AN&W'R(
hen a detection algorithm determines that a deadlock eists# several alternatives are
available. 1ne possibility is to inform the operator that a deadlock has occurred and to let the
operator deal with the deadlock manually. Another possibility is to let the system recover
from the deadlock automatically. There are two options for breaking a deadlock. 1ne is
simply to abort one or more processes to break the circular wait. The other is to preempt
some resources from one or more of the deadlocked processes.
Process Termination
To eliminate deadlocks by aborting a process# we use one of two methods. In both
methods# the system reclaims all resources allocated to the terminated processes.
A$ort all "ea"loc7e" processes+ This method clearly will break the deadlock cycle#
but at great epense* the deadlocked processes may have computed for a long time#
and the results of these partial computations must be discarded and probably will have
to be recomputed later.
A$ort one process at a time until the "ea"loc7 cycle is eliminate"+ This method
incurs considerable overhead# since# after each process is aborted# a deadlock+
detection algorithm must be invoked to determine whether any processes are still
deadlocked.
Resource Preemption
To eliminate deadlocks using resource preemption# we successively pre+empt some resources
from processes and give these resources to other processes until the deadlock cycle is broken.
If preemption is re$uired to deal with deadlocks# then three issues need to be addressed'
1+ &electing a victim. hich resources and which processes are to be preemptedQ As in
process termination# we must determine the order of preemption to minimi&e cost.
ost factors may include such parameters as the number of resources a deadlocked
process is holding and the amount of time the process has thus far consumed duringits eecution.
24
-
7/24/2019 os 24
25/25
+ Roll$ac7. If we preempt a resource from a process# what should be done with that
processQ learly# it cannot continue with its normal eecution* it is missing some
needed resource. e must roll back the process to some safe state and restart it from
that state. %ince# in general# it is difficult to determine what a safe state is# the simplest
solution is a total rollback' Abort the process and then restart it.
3+ &tarvation+;ow do we ensure that starvation will not occurQ That is how can we
guarantee that resources will not always be preempted from the same processQ
5) e!ine "ea"loc7? What are the !our con"itions that hol" simultaneously in a
system !or the "ea"loc7 situation to arise?
AN&W'R(
A process re$uests resources* and if the resources are not available at that time# the
process enters a waiting state. %ometimes# a waiting process is never again able to change
state# because the resources it has re$uested are held by other waiting processes. Thissituation is called a "ea"loc7+
A process may utili&e a resource in only the following se$uence'
1+ Re:uest+ If the re$uest cannot be granted immediately (for eample# if the resource is
being used by another process)# then the re$uesting process must wait until it can
ac$uire the resource.
+ Use# The process can operate on the resource (for eample# if the resource is a printer#
the process can print on the printer)
3+ Release+The process releases the resource.
Necessary on"itions(
A deadlock situation can arise if the following four conditions hold simultaneously in
a system'
4utual e*clusion+ At least one resource must be held in a non+sharable mode* that is#
only one process at a time can use the resource. If another process re$uests that
resource# the re$uesting process must be delayed until the resource has been released.
6ol" an" %ait+ A process must be holding at least one resource and waiting to
ac$uire additional resources that are currently being held by other processes.
No preemption+ Cesources cannot be preempted* that is# a resource can be releasedonly voluntarily by the process holding it# after that process has completed its task.
ircular %ait. A set R4# 46# ...# 4nS of waiting processes must eist such that 4 is
waiting for a resource held by 46# 46is waiting for a resource held by 42# # 4n+6 is
waiting for a resource held by 4n# and 4n is waiting for a resource held by 4.