8th Lecture OS
8th Lecture OS
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.
A deadlock
. Set of N processes
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
Disk drive
Printer
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:
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.