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

8th Lecture OS

Uploaded by

farwakhalid146
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

8th Lecture OS

Uploaded by

farwakhalid146
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

OPERATING SYSTEM

CS(407)

LECTURE 8
DEADLOCK

INSTRUCTOR
SIBGHA ZIA
DEPARTMENT OF COMPUTER SCIENCE
UAF SUB CAMPUS BUREWALA
DEADLOCK
 Multiprogramming operating system has ability to execute multiple
programs with using of only one processor machine . One example is
User can use MS-Excel , download apps, transfer data from one point
to another point, Firefox or Google Chrome browser, and more at a
same time.

 In multiprogramming environment, several processes are compete for


resources. A situation may arises where a process is waiting for a
resource that is held by waiting processes. This situation is called
dead lock
DEADLOCK
 Deadlock is a common problem in multi-processing where several
processes share a specific type of mutually exclusive resource known
as a soft lock.

A deadlock
 . Set of N processes

 . Each waiting for an event

 ...which can be caused only by another process in the set

 Every process will wait forever


DEAD LOCK EXAMPLE 1
 A real-world example would be traffic, which is going only in one
direction. Here, a bridge is considered a resource. So, when Deadlock
happens, it can be easily resolved if one car backs up (Preempt
resources and rollback). Several cars may have to be backed up if a
deadlock situation occurs
DEAD LOCK EXAMPLE 2
 When two train approach each other at crossing, both shall come to
full stop and neither will startup again until the other has gone.
EXAMPLES
 Suppose you have printer and tape drive.
 Process A request for the printer and gets it.

 Process B request tape drive and it is gained to it.

 Now A asks for the tape drive but the request is denied until B release
it.
 At this point, the process B asks for the printer before releasing the
tape drive.
 Both processes are waiting for each other to release the resource and
are blocked. Both process will remain in this situation forever.
 This situation is called Deadlock
B

Tape
Printer
drive

A
EXAMPLES OF DEADLOCK
 Simplest form
 . Process 1 owns printer, wants tape drive

 . Process 2 owns tape drive, wants printer

 Every process will wait forever


RESOURCES
 A recourse is an object that is used by process. T can be a piece of
hardware.
 Tape drive

 Disk drive

 Printer

 A recourse can be a piece of information such as

 File

 A record within file

 A shared variable
RESOURCE…
 A computer typically has many resources. In some case, there may
be many instances of a resource of a given time. A process needing
one of these resources can use any one them. In other cases there
may be only one instance of a resource.
TYPES OF RESOURCES

 Preemptible Resources
 Non-Preemptible Resources
PREEMPTIBLE RESOURCES

 Preemptible, meaning that the resource can be taken away from its
current owner (and given back later).
 A Preemptible resources is one can be allocated to a given process for
a period of time. Then it can be allocated to another process. Then It can
be reallocate to the first process without any negative effect
 Example:

An example is memory, buffer, CPU, and array processor.


NON-PREEMPTIBLE RESOURCES
 Non- Preemptible, meaning that the resource cannot be taken away.
 A Non- Preemptible resource cannot be taken from one process and
given to another without side effect.
 Example:

 An example is a printer. A printer cannot be take away from one


process and given to another process in the middle of a print job.
Dead lock usually involves non- Preemptible resources.
DEADLOCK CHARACTERIZATION

 Deadlock can arise if four conditions


hold simultaneously:

I. Mutual Exclusion
II. Hold and Wait
III. No Preemption
IV. Circular Wait
 Mutual Exclusion
 Mutual Exclusion only one process at a time can use a resource.
If another process requests that resource, the requesting process must be
delayed until the resource has been released.
 Hold and wait
 Hold and wait a process that holding at least one resource is waiting to acquire
additional resources held by other processes.
 No Preemption
 No preemption a resource can be released only voluntarily by the process
holding it, after that process has completed its task.
 Circular Wait:
 There exists a set {P0, P1, …, P0} of waiting processes such that P0 is
waiting for a resource that is held by P1,P1is waiting for a resource that is held
by P2, …, Pn–1is waiting for a resource that is held by Pn, and P0is waiting for
a resource that is held by P0.
RESOURCE ALLOCATION GRAPH
 A resource allocation graph is used to describe a deadlock graphically.
 The graph has two different types of nodes. i.e. Process node and
resource nodes.
 Process represent by circle and resources represent by rectangles.for
each instance of a resource, there is a dot in the resource node
rectangle.
 For Example, if there are two identical printers, the printer resource
will have two dots. The edge among nodes represent resource
allocation and request.
 If edge goes from resource to process node, it indicates that the
process has acquire the resource. If edge goes from process node to
resource node, it indicates that the process has requested the
resource.

You might also like