Banker`s Algorithm Developed by Dijkstra in 1965

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Deadlock 2.
Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks (Continuation). 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks.
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
DPNM Lab. Dept. of CSE, POSTECH
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
03/07/2007CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
03/03/2004CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Deadlock Characterization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 28 Handling Deadlock.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
13/03/07Week 21 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Operating System Concepts and Techniques Lecture 15 Deadlock and starvation-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,
Deadlocks System Model RAG Deadlock Characterization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Chapter 7: Deadlocks.
G.Anuradha Ref:- Galvin
Chapter 6 : Deadlocks What is a Deadlock?
Chapter 7: Deadlocks.
Chapter 7 Deadlocks.
Process Deadlocks.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
Chapter 7: Deadlocks.
CSCI 315 Operating Systems Design
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Presentation transcript:

Banker`s Algorithm Developed by Dijkstra in 1965 A deadlock avoidance algorithm Each process provides information about the resources it will need in order to complete execution

Deadlock Avoidance Requires that the system has some additional a priori information available. 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 A resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes

Banker’s Algorithm Used when there exists multiple instances of a resource type Each process must a priori claim maximum use 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 Always keep so many resources that satisfy the needs of at least one client

Banker’s Algorithm Based on a bank with a fixed amount of capital that operates on the following principles: No customer will be granted a loan exceeding bank’s total capital. All customers will be given a maximum credit limit when opening an account. No customer will be allowed to borrow over the limit. The sum of all loans won’t exceed the bank’s total capital. OS (bank) must be sure never to satisfy a request that moves it from a safe state to an unsafe one. Job with smallest number of remaining resources < = number of available resources

Banker`s Algorithm (Contd….) Processes are like customers wanting to borrow money (resources) from a bank... A banker should not allocate cash when it cannot satisfy the needs of all its customers

Safe and Unsafe states The state of the system is the current allocation of resources to processes. A safe state is one in which there is at least one order in which all processes can be run to completion within a finite time without resulting in a deadlock. (It is possible to go from a safe state to an unsafe state.) The OS is analogous to a banker, and job requests are analogous to the clients. The system grants requests that result in safe states only. Unsafe states need not be deadlocked ; there is only a potential for deadlock. The banker’s algorithm assures that there is never such a possibility.

Banker’s Algorithm Assume that: a resource can have multiple instances the OS has N processes, M resource types Initially, each process must declare the maximum no. of resources it will need. Calculate a safe sequence if possible.

Safe and Unsafe state A safe state cannot lead to deadlock. An unsafe state may lead to deadlock. Deadlock is avoided by always keeping the system in a safe state (though this may reduce resource utilization) Deadlock Unsafe Safe

Example 1 Max no. of resources: 12 tape drives Max needs Current Allocation P0 10 5 P1 4 2 P2 9 2 Currently, there are 3 free tape drives The OS is in a safe state, since <P1, P0, P2> is a safe sequence.

Example 2 Same as last slide, but P2 now has 3 tape drives allocated currently. Max needs Current Allocation P0 10 5 P1 4 2 P2 9 3 The OS is in an unsafe state.

Example 3 Suppose we have two resources, A, and B. A has 6 instances and B has 3 instances. Can the system execute the following processes without deadlock occurring?

Solution Available: A= 1; B= 0 We can execute the processes in the sequence <P4, P1, P3, P2, P5> without deadlock.

Example 4 Consider six processes P0, P1…P5 and three resources A, B and C. Is executing the following processes a safe state.

Solution First find the resources that each process needs The process is in safe state it is executed in the order (P1, P3, P4, P0, P2, P5)

Example 5 Suppose we have five processes and three resources A, B and C. A has 2 instances, B has 5 instances and C has 4 instances. Given the information below, can the system execute the following processes without deadlock occurring,.

Solution The Available is A=0, B=1 and C=0 The current need is

Example 6

Solution

Question

Problems with Banker’s Algorithm . Users must state their maximum resource usage in advance, but many jobs are interactive and dynamic and users cannot anticipate their eventual requirements. Processes rarely know in advance how many resources they will need The number of processes changes as time progresses Resources once available can disappear The algorithm assumes processes will return their resources within a reasonable time Processes may only get their resources after an arbitrarily long delay