Chapter - 4. Deadlocks Important Questions

Similar documents
Deadlock Prevention. Restrain the ways request can be made. Mutual Exclusion not required for sharable resources; must hold for nonsharable resources.

Deadlocks. Deadlock Overview

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks

The Deadlock Problem

Chapter 7: Deadlocks

Chapter 8: Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem. System Model. Bridge Crossing Example. Resource-Allocation Graph. Deadlock Characterization

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS307: Operating Systems

CSE Opera+ng System Principles

System Model. Types of resources Reusable Resources Consumable Resources

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem. Chapter Objectives. System Model. Bridge Crossing Example

Chapter 8: Deadlocks. The Deadlock Problem

CS307 Operating Systems Deadlocks

Chapter 7: Deadlocks

Deadlocks. Bridge Crossing Example. The Problem of Deadlock. Deadlock Characterization. Resource-Allocation Graph. System Model

Chapter 7 : 7: Deadlocks Silberschatz, Galvin and Gagne 2009 Operating System Concepts 8th Edition, Chapter 7: Deadlocks

Module 7: Deadlocks. The Deadlock Problem

Module 6: Deadlocks. Reading: Chapter 7

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

CMSC 412. Announcements

UNIT-5 Q1. What is deadlock problem? Explain the system model of deadlock.

Module 7: Deadlocks. System Model. Deadlock Characterization. Methods for Handling Deadlocks. Deadlock Prevention. Deadlock Avoidance

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 7 Deadlocks. Zhi Wang Florida State University

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,! Silberschatz, Galvin and Gagne 2009!

Deadlock. Concepts to discuss. A System Model. Deadlock Characterization. Deadlock: Dining-Philosophers Example. Deadlock: Bridge Crossing Example

Chapter 7: Deadlocks

Bridge Crossing Example

The Deadlock Problem

Chapter 8: Deadlocks. Operating System Concepts with Java

Deadlocks. Dr. Yingwu Zhu

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

Roadmap. Safe State. Deadlock Avoidance. Basic Facts. Safe, Unsafe, Deadlock State. Tevfik Koşar. CSC Operating Systems Spring 2007

The Deadlock Problem (1)

Chapter 7: Deadlocks. Operating System Concepts 8th Edition, modified by Stewart Weiss

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Principles of Operating Systems

The deadlock problem

Deadlock Risk Management

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Roadmap. Deadlock Prevention. Deadlock Prevention (Cont.) Deadlock Detection. Exercise. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Potential Deadlock Example

Chapter 7: Deadlocks. Operating System Concepts 9th Edition DM510-14

Principles of Operating Systems

CSC Operating Systems Fall Lecture - XII Deadlocks - III. Tevfik Ko!ar. Louisiana State University. October 6 th, 2009

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

Lecture 7 Deadlocks (chapter 7)

ICS Principles of Operating Systems. Lectures Set 5- Deadlocks Prof. Nalini Venkatasubramanian

CHAPTER 7: DEADLOCKS. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Deadlocks. Prepared By: Kaushik Vaghani

CHAPTER 7 - DEADLOCKS

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

CS370 Operating Systems

Silberschatz, Galvin and Gagne 2013! CPU cycles, memory space, I/O devices! " Silberschatz, Galvin and Gagne 2013!

Final Exam Review. CPSC 457, Spring 2016 June 29-30, M. Reza Zakerinasab Department of Computer Science, University of Calgary

CS420: Operating Systems. Deadlocks & Deadlock Prevention

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition! Silberschatz, Galvin and Gagne 2013!

Chapter 7: Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

The Deadlock Problem

CS370 Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Operating Systems. Deadlock. Lecture 7 Michael O Boyle

Chapter 8: Deadlocks. The Deadlock Problem

OPERATING SYSTEMS. Deadlocks

Introduction to Deadlocks

Chapter 7: Deadlocks CS370 Operating Systems

Chapter 7: Deadlocks. Chapter 7: Deadlocks. System Model. Chapter Objectives

Deadlock. Chapter Objectives

Chapter 7: Deadlocks. Chapter 7: Deadlocks. Deadlock Example. Chapter Objectives

University of Babylon / College of Information Technology / Network Department. Operating System / Dr. Mahdi S. Almhanna & Dr. Rafah M.

The Deadlock Problem. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

Deadlock. A Bit More on Synchronization. The Deadlock Problem. Deadlock Characterization. Operating Systems 2/7/2005. CSC 256/456 - Spring

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Deadlock Risk Management

Operating Systems. Deadlocks. Stephan Sigg. November 30, Distributed and Ubiquitous Systems Technische Universität Braunschweig

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

CS370 Operating Systems

CS370 Operating Systems

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

CS370 Operating Systems

CSC 539: Operating Systems Structure and Design. Spring 2005

TDDB68 + TDDD82. Lecture: Deadlocks

Operating systems. Lecture 5. Deadlock: System Model. Deadlock: System Model. Process synchronization Deadlocks. Deadlock: System Model

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Deadlocks. System Model

Contents. Chapter 8 Deadlocks

Deadlocks. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Deadlocks. The Deadlock Problem. Bridge Crossing Example. Topics

ECE519 Advanced Operating Systems

Chapter 8: Deadlocks. The Deadlock Problem

The Deadlock Problem. Chapter 8: Deadlocks. Bridge Crossing Example. System Model. Deadlock Characterization. Resource-Allocation Graph

Topic 4 Scheduling. The objective of multi-programming is to have some process running at all times, to maximize CPU utilization.

Outlook. Deadlock Characterization Deadlock Prevention Deadlock Avoidance

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Transcription:

Chapter - 4 Deadlocks Important Questions 1

1.What do you mean by Deadlocks? A process request for some resources. If the resources are not available at that time, the process enters a waiting state. The resources was held by other processes.the waiting process may never able to get the resource. This situation is called deadlock. 2

2. What are the necessary conditions for deadlocks? Mutual exclusion: only one process at a time can use a resource. If another process requests the same resource, the requesting process must wait until the resource is released. Hold and wait: Processes currently holding resources granted earlier, can request for new resources, that are currently held by other. 3

No preemption: a resource can be released by the process holding it only after that process has competed its task. Circular wait: The circular chain of two or more processes must exist such that each of them is waiting for a resource held by next member. There exists a set {P 0, P 1,, P n } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2,, P n 1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0. 4

Circular wait 5

3. Explain the Resource allocation graph in detail. A set of vertices V and a set of edges E. V is partitioned into two types: P = {P 1, P 2,, P n }, the set consisting of all the processes in the system R = {R 1, R 2,, R m }, the set consisting of all resource types in the system request edge directed edge P i R j assignment edge directed edge R j P i 6

Resource allocation graph Process Resource Type with 4 instances P i requests instance of R j P i P i is holding an instance of R j P i 7

Example for Resource allocation graph 8

Resource allocation graph with deadlock 9

Graph With A Cycle 10

Basic Facts If graph contains no cycles no deadlock If graph contains a cycle if only one instance per resource type, then deadlock if several instances per resource type, possibility of deadlock 11

4. Explain the concept of Deadlock prevention in detail Mutual exclusion Hold and wait No pre-emption Circular wait 12

Mutual Exclusion Not always possible to prevent deadlock by preventing mutual exclusion (making all resources shareable) as certain resources are cannot be shared safely. Hold and Wait A process can get all required resources before it start execution. This will avoid deadlock, but will result in reduced throughputs as resources are held by processes even when they are not needed. They could have been used by other processes during this time. Second approach is to request for a resource only when it is not holding any other resource. 13

No preemption We will see two approaches here. If a process request for a resource which is held by another process, then the resource may be preempted from the other process. In the second approach, if a process request for a resource which are not readily available, all other resources that it holds are preempted. Circular wait To avoid circular wait, resources may be ordered and we can ensure that each process can request resources only in an increasing order of these numbers. The algorithm may itself increase complexity and may also lead to poor resource utilization. 14

5. Explain Banker s Algorithm in detail Multiple instances When a process requests a resource it may have to wait When a process gets all its resources it must return them in a finite amount of time 15

Banker s algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that is applicable to resource allocation systems with multiple instances of each resource type. The Bankers algorithm is run by operating system whenever a process requests resources. The algorithm must determine whether allocation of these resources will put the system in a safe state. If true, the resources will be allocated. Otherwise,the process must wait until some other process runs to completion and releases enough resources 16

Data Structures for the Banker s Algorithm Let n = number of processes, and m = number of resources types. Available: Vector of length m. If available [j] = k, there are k instances of resource type R j available Max: n x m matrix. If Max [i,j] = k, then process P i may request at most k instances of resource type R j Allocation: n x m matrix. If Allocation[i,j] = k then P i is currently allocated k instances of R j Need: n x m matrix. If Need[i,j] = k, then P i may need k more instances of R j to complete its task Need [i,j] = Max[i,j] Allocation [i,j] 17

Safety Algorithm Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i = 0, 1,, n- 1 2. Find an i such that both: (a) Finish [i] = false (b) Need i Work If no such i exists, go to step 4 3. Work = Work + Allocation i Finish[i] = true go to step 2 4. If Finish [i] == true for all i, then the system is in a safe state 18

Resource-Request Algorithm for Process P i Request i = request vector for process P i. If Request i [j] = k then process P i wants k instances of resource type R j 1. If Request i Need i go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim 2. If Request i Available, go to step 3. Otherwise P i must wait, since resources are not available 3. Pretend to allocate requested resources to P i by modifying the state as follows: Available = Available Request i ; Allocation i = Allocation i + Request i ; Need i = Need i Request i ; If safe the resources are allocated to P i If unsafe P i must wait, and the old resource-allocation state is restored 19

Example of Banker s Algorithm 5 processes P 0 through P 4 ; 3 resource types: A (10 instances), B (5instances), and C (7 instances) Snapshot at time T 0 : Allocation Max Available A B C A B C A B C P 0 0 1 0 7 5 3 3 3 2 P 1 2 0 0 3 2 2 P 2 3 0 2 9 0 2 P 3 2 1 1 2 2 2 P 4 0 0 2 4 3 3 20

The content of the matrix Need is defined to be Max Allocation Need A B C P 0 7 4 3 P 1 1 2 2 P 2 6 0 0 P 3 0 1 1 P 4 4 3 1 The system is in a safe state since the sequence < P 1, P 3, P 4, P 2, P 0 > satisfies safety criteria 21

6. Explain the Deadlock detection algorithm for single and multiple instance type Single Instance of Each Resource Type Maintain wait-for graph Nodes are processes P i P j if P i is waiting for P j Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock 22

Resource-Allocation Graph and Waitfor Graph 23

Several Instances of a Resource Type Available: A vector of length m indicates the number of available resources of each type Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process Request: An n x m matrix indicates the current request of each process. If Request [i][j] = k, then process P i is requesting k more instances of resource type R j. 24

Detection algorithm 1)Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work = Available (b)for i = 1,2,, n, if Allocation i 0, then Finish[i] = false; otherwise, Finish[i] = true 2. Find an index i such that both: (a)finish[i] == false (b)request i Work If no such i exists, go to step 4 25

Work = Work + Allocation i Finish[i] = true go to step 2 4.If Finish[i] == false, for some i, 1 i n, then the system is in deadlock state. 26

7. Explain the concept of Deadlock recovery Process termination Resource pre-emption Check point / roll back mechanism 27

Process termination Abort all deadlocked process Successively abort each deadlocked process until the deadlock no longer exists. 28

Resource pre-emption Roll back A process that has a resource pre-empted from it must be roll back to the point to its acquiring of that resource. Total roll back Abort the process and restart it. 29

Check point Keep checkpointing periodically When a deadlock is detected, see which resource is needed Take away the resource from the process currently having it Restart the process from the checkpointed state. 30

8.What is safe state? Safe State state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock. More formally, a system is in a safe state only if there exists a safe sequence. 31