21
 DCS5058 Operating S ystems Tri56 (2013/2014) 1 Introduction We Manishankar, Sasitharan, Chan Wei Jian and Thanieeswaraan are the CDP students of Multimedia University Cyberjaya Campus. We are focusing on the topic Deadlock which is one of the topics from the subject Operating System. Our intention of this assignment is to explain about the topic deadlock and also the Banker’s Algorithm which is used to identify the state of the system whether it is in a safe state or there is possibility of deadlock.

Introduction - Appendix (1)

Embed Size (px)

Citation preview

Page 1: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 1/21

 DCS5058 Operating Systems Tri56 (2013/2014)

1

Introduction

We Manishankar, Sasitharan, Chan Wei Jian and Thanieeswaraan are the CDP

students of Multimedia University Cyberjaya Campus. We are focusing on the topic

Deadlock which is one of the topics from the subject Operating System. Our intention of this

assignment is to explain about the topic deadlock and also the Banker’s Algorithm which is

used to identify the state of the system whether it is in a safe state or there is possibility of

deadlock.

Page 2: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 2/21

 DCS5058 Operating Systems Tri56 (2013/2014)

2

Objective

  To be able to describe deadlock.

  To introduce and explain system model and resource allocation graph in details.

  To understand deadlock characteristics.

  To explain methods for handling deadlocks such deadlock prevention, deadlock

avoidance and deadlock recovery.

  To apply on Banker’s algorithm to identify whether the system is in a safe state or

there are any possibilities of deadlock.

Page 3: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 3/21

 DCS5058 Operating Systems Tri56 (2013/2014)

3

SCOPE

Identifying the state whether is it safe or there are any possibilities of deadlock by using

Banker’s Algorithm. 

Example question and its solution:

Consider a system with 5 processes: P0, P1, P2, P3, P4; three resource type: A (10

instances), B (5 instances), C (7 instances).

Allocation Max

1)  Draw a Resource Allocation Graph.

2)  Is the system safe? Use Banker’s algorithm to prove it.  

3) 

Suppose now P1 request additional instances (1, 0, 2). Can it be granted?

4) 

Can request (3, 3, 0) from P4 be granted? Provide your reason.

5)  Can request (0, 2, 0) from P0 be granted? Provide your reason.

Page 4: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 4/21

 DCS5058 Operating Systems Tri56 (2013/2014)

4

Page 5: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 5/21

 DCS5058 Operating Systems Tri56 (2013/2014)

5

Page 6: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 6/21

 DCS5058 Operating Systems Tri56 (2013/2014)

6

Page 7: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 7/21

 DCS5058 Operating Systems Tri56 (2013/2014)

7

Page 8: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 8/21

 DCS5058 Operating Systems Tri56 (2013/2014)

8

Page 9: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 9/21

 DCS5058 Operating Systems Tri56 (2013/2014)

9

Page 10: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 10/21

 DCS5058 Operating Systems Tri56 (2013/2014)

10

Page 11: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 11/21

 DCS5058 Operating Systems Tri56 (2013/2014)

11

Page 12: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 12/21

 DCS5058 Operating Systems Tri56 (2013/2014)

12

Page 13: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 13/21

 DCS5058 Operating Systems Tri56 (2013/2014)

13

Deadlock

Definition

In a multiprogramming system, processes request resources. If those resources are

 being used by other processes then the process enters a waiting state. However, if other

 processes are also in a waiting state, we have deadlock. The formal definition of deadlock is

as follows:

A set of processes is in a deadlock state if every process in the set is waiting for an

event (release) that can only be caused by some other process in the same set.

Example

Process-1 requests the printer, gets it

Process-2 requests the tape unit, gets it Process-1 and

Process-1 requests the tape unit, waits Process-2 are

Process-2 requests the printer, waits deadlocked!

Deadlocks shall be analysed with the following assumptions:

• A process must request a resource before using it. It must release the resource after using it.(request - use - release)

• A process cannot request a number more than the total number of resources available in the

system.

For the resources of the system, a resource table shall be kept, which shows whether each

 process is free or if occupied, by which process it is occupied. For every resource, queues

shall be kept, indicating the names of processes waiting for that resource.

Page 14: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 14/21

 DCS5058 Operating Systems Tri56 (2013/2014)

14

Resource Allocation Graphs

Resource allocation graphs are drawn in order to see the allocation relations of

 processes and resources easily. In these graphs, processes are represented by circles and

resources are represented by boxes. Resource boxes have some number of dots inside

indicating available number of that resource that is number of instances.

• If the resource allocation graph contains no cycles then there is no deadlock in the

system at that instance.

• If the resource allocation graph contains a cycle then a deadlock may exist.

• If there is a cycle, and the cycle involves only resources which have a single

instance, then a deadlock has occurred.

Resource Allocation Graph

Page 15: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 15/21

 DCS5058 Operating Systems Tri56 (2013/2014)

15

Example of Resource Allocation Graph

Example of Resource Allocation Graph with a Deadlock

Page 16: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 16/21

 DCS5058 Operating Systems Tri56 (2013/2014)

16

Characteristics of Deadlock

A deadlock situation can arise if the following four conditions hold simultaneously in a

system:

Mutual exclusion:

At least one resource must be held in a non-sharable mode. The only one process at a time

can use the resource. If another process requests that resources, the requesting process must

 be delayed until the resource has been released.

Hold and wait:

There must be a process that is holding at least one resource and is waiting to acquire

additional resources that are currently being held by other processes.

 No pre-emption:

Resources cannot be pre-empted. The resource can be released only voluntarily by the

 process holding it, after that process has completed its task.

Circular wait:

There must exist a set {P0, P1,…, Pn} of waiting processes such that P0 is waiting for aresource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn-1 is waiting

for resource that is held by Pn, and Pn is waiting for a resource that is held by P0.

Page 17: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 17/21

 DCS5058 Operating Systems Tri56 (2013/2014)

17

Methods for Handling Deadlocks

Ensure that the system will never enter a deadlock state. Allow the system to enter a deadlock

state and then recover. Ignore the problem and pretend that deadlocks never occur in the

system.

Deadlock Prevention

Mutual Exclusion  –   Not required for sharable resources and must hold for non-sharable

resources.

Hold and Wait –  Must guarantee that whenever a process requests a resource, it does not hold

any other resources.

Require process to request and be allocated all its sources before it begins execution, or allow

 process to request resources only when the process has none. Low resource utilization;

starvation possible. Restrain the ways request can be made.

 No Pre-emption –  If a process that is holding some resources requests another resource that

cannot be immediately allocated to it, and then all resources currently being held are released.

Pre-empted resources are added to the list of resources for which the process is waiting.

Process will be restarted only when it can regain its old resources, as well as the new ones

that it is requesting.

Circular Wait –   Impose a total ordering of all resource types, and require that each process

requests resources in an increasing order of enumeration

Page 18: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 18/21

 DCS5058 Operating Systems Tri56 (2013/2014)

18

Deadlock Avoidance

Simplest and most useful model requires that each process declare the maximum number of

resources of each type that it may need.

The deadlock-avoidance algorithm dynamically examines the resource-allocation state to

ensure that there can never be a circular-wait condition.

Resource-allocation state is defined by the number of available and allocated resources, and

the maximum demands of the processes.

Requires that the system has some additional a priority information available.

Deadlock Recovery

Recovery idea is to get rid of the cycles in the process dependency graph.

•  Kill all deadlocked processes

•  Kill one deadlocked process at a time and release its resources

•  Steal one resource at a time

•  Roll back all or one of the processes to a checkpoint that occurred before they requested

any resources, then continue difficulties to prevent indefinite postponement.

What should be considered before picking a process to kill?

•  process priority

•  current computation time and time to completion

•  amount of resources used by the process

•  amount of resources needed by the process to complete

•  the minimal set of processes we need to eliminate to break deadlock

•  is process interactive or batch? 

Page 19: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 19/21

 DCS5058 Operating Systems Tri56 (2013/2014)

19

Conclusion

After using the Banker’s Algorithm to identify the safe state: 

  If the final new available is equals to the total instances, it means the deadlock can be

avoided. There is a safe sequence and the system is in a safe state.

  If the final new available is not equals to the total instances, it means the system is not

safe. There is possibility of deadlock.

Page 20: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 20/21

 DCS5058 Operating Systems Tri56 (2013/2014)

20

Reference

  http://courses.engr.illinois.edu/cs241/sp2012/lectures/28-deadlock-solutions.pdf  

  http://www.eee.metu.edu.tr/~halici/courses/442/Ch5%20Deadlocks.pdf  

  http://stackoverflow.com/questions/2485608/what-the-difference-between-deadlock-

avoidance-and-deadlock-prevention 

  Chapter_6_-_Deadlock (Notes provided in lecture session)

  http://en.wikibooks.org/wiki/Operating_System_Design/Concurrency/Deadlock  

Page 21: Introduction - Appendix (1)

8/12/2019 Introduction - Appendix (1)

http://slidepdf.com/reader/full/introduction-appendix-1 21/21

 DCS5058 Operating Systems Tri56 (2013/2014)

Appendix

In computer science, deadlock refers to a specific condition when two or more

 processes are each waiting for another to release a resource, or more than two processes are

waiting for resources in a circular chain. Deadlock is a common problem in multiprocessing

where many processes share a specific type of mutually exclusive resource known as

a software, or soft, lock. Computers intended for the time-sharing  and/or real-time markets

are often equipped with a hardware lock  which guarantees exclusive access to processes,

forcing serialization. Deadlocks are particularly troubling because there is no general  solution

to avoid deadlocks.

This situation may be understood by an analogy with two people who are drawing

diagrams, with only one pencil and one ruler between them. If one person takes the pencil

and the other takes the ruler, a deadlock occurs when the person with the pencil needs the

ruler and the person with the ruler needs the pencil, before he can give up the ruler. Both

requests can't be satisfied, so a deadlock occurs.

The telecommunications description of deadlock is a little stronger. Deadlock occurs

when none of the processes meet the condition to move to another state and all the

communication channels are empty. The second condition is often left out on other systems

 but is important in the telecommunication context.