Operating systems Deadlocks.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 5 Deadlocks. Contents What is deadlock? What is deadlock? Characterization Characterization Resource allocation graph Resource allocation graph.
OPERATING SYSTEMS DEADLOCKS
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
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.
02/18/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Chapter 7.1: Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
7: Deadlocks1 DEADLOCKS EXAMPLES: "It takes money to make money". You can't get a job without experience; you can't get experience without a job. BACKGROUND:
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Deadlocks System Model RAG Deadlock Characterization
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
1 OPERATING SYSTEMS DEADLOCKS created by:-gaurav shrivastava contact:- om.
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.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7: Deadlocks1 OPERATING SYSTEMS DEADLOCKS. 7: Deadlocks2 What Is In This Chapter? What is a deadlock? Staying Safe: Preventing and Avoiding Deadlocks.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
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.
Chapter 7: Deadlocks.
ITEC 202 Operating Systems
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
OPERATING SYSTEMS DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Process Deadlocks.
Chapter 7: Deadlocks.
Operating systems Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
CSc 552 Advanced Unix Process deadlock deadlock prevention
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
DEADLOCK.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
IT3002 Computer Architecture
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
DEADLOCKS.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Chapter 8: Deadlocks Deadlock Characterization
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Operating systems Deadlocks

Deadlocks What is a deadlock? 2 approaches: “safe”: prevent and avoid deadlocks “dangerous”: it enables a deadlock appearance, then detect it and solve the problem “a deadlock is a state in which each member of a group of actions, is waiting for some other member to release a lock”

Deadlocks Examples: “It takes money to make money".   “It takes money to make money". You cannot have a job without experience; you cannot have experience without a job. Deadlock causes: each process needs an output form other process. This fact has the result of resource sharing (memory, equipment, connection links, etc). In a normal situation, the operation of resource allocation is done like this:  The resource is demanded. The resource is used. The resource is freed-up.

Example: crossing a bridge One direction only traffic. Each section of the bridge can be considered as a resource. If a deadlock occurs, it can be solved if one of the cars goes back (resource preemption). It can appear the phenomenon of “starvation”. See also the 5 philosophers problem: (http://en.wikipedia.org/wiki/Dining_philosophers_problem)

Deadlock characteristics Necessary conditions  All 4 conditions must happen simultaneously in order to have a deadlock: Mutual exclusion One or more resources must be owned by a process in an exclusive way.   “Hold and Wait” A process owns a resource while is waiting for another resource to be freed-up. No preemption We have only the possibility that a resource is freed-up voluntarily – nothing else can force to freed-up the resource. Circular waiting The process A waits for process B that waits for process C .... that waits for A. http://www.personal.kent.edu/~rmuhamma/OpSystems/Myos/deadlockCondition.htm

Resource allocation graph A graph can be used to visually determine the appearance (or the possibility of appearance) of a deadlock.   G = ( N, L ) nodes (vertices) and links (edges) N The nodes are processes= {P1, P2, P3, ...} and different types of resources {R1, R2, ...} M The links are ( Pi, Rj ) or ( Ri, Pj ) An arrow from one process to a resource means that the process needs that resource. An arrow from a resource to a process means that an instance of that resource has been allocated to that process.  In the drawing, the process is a circle, the resource is a square; the dots are representing the number of instances for that specific resource.

Resource allocation graph If the graph has no cycles, no process is blocked. If there is a cycle, then: a) If the types of resources have more instances, then it MIGHT exist a deadlock. b) If every type of resource has a single instance, a deadlock will appear. R3 assigned to P3 Resource allocation graph P2 requests R3

General strategies for approaching deadlocks   In general, there are three methods: - Ignoring deadlocks. - Assuring the fact that a deadlock can never appear: Prevention Preventing the appearance of one of the four conditions (Mutual exclusion,“Hold and Wait”, No preemption, Circular waiting). Avoidance The deadlock conditions are enabled but the appearance cycles are computed and the dangerous operations are stopped.    - Enabling the deadlock appearance. In this case there are used the following: Detection The moment when a deadlock has appeared is known. Recovery The resources are “recovered”.

Preventing deadlocks None of the four conditions cannot appear Mutual exclusion: a) It is automated for printers and other non-sharable devices b) Entities like read only files don’t need mutual exclusion, because they cannot lead to deadlocks.   “Hold and wait”: a) All the resources are gathered before the execution b) One particular resource can be demanded only when nobody holds it. In a sequence of resources the first one is demanded first. c) In this case “starvation” may occur.

Preventing deadlocks No preemption:   a) Any assigned resource is freed-up if the process cannot obtain another resource. b) If a resource is assigned to a process involved in a waiting state for another resource, this is “stealed”. Circular waiting: a) The resources are numbered and their demand is done in ascending order b) Each of the preventing methods can lead to a low resource utilization. For this reason, prevention is not necessarily the best method to implement. c) Prevention is the easiest method to implement

Deadlock avoidance If we can know from he beginning the way of using resources it is possible to determine if an “unsafe” state can appear. Possible states:   Deadlock Nothing “constructive” can be done furthermore Unsafe state A state for which a deadlock may occur Safe state A state is safe if there is a sequence of processes such as there are enough resources for the first process to finish and each process is finishing and freeing the necessary resources for the next process to finish. A simple rule: “if a resource demand allocation may lead to an unsafe state, don’t satisfy that demand”. Obs. All the deadlocks are unsafe, but not all unsafe states are deadlocks

Process concurrency in Unix/Linux UNIX offers many mechanisms for communication and synchronization between processes: Pipes Messages Shared memory Semaphores Signals Pipes – a pipe represents a circular buffer that enables the communication between two processes using the “producer-consumer” pattern – a FIFO queue where a process sends a message to another process. When a pipe is created, it has a fixed dimension in bytes. When a process tries to write in the pipe the writing demand is immediately executed (if there is enough space, otherwise the process is blocked). In the same way, a process that needs a reading operation is blocked if it tries to read more octets than exist in the pipe – on the contrary, the reading demand is immediately executed. The OS applies mutual exclusion in this case – only a single process may access the pipe at one moment in time.

Process concurrency in Unix/Linux Messages – A message is a block of text of a certain type. The UNIX OS uses the system calls msgsnd and msgrcv to transfer messages. Each process has a message queue that is working as a mailbox. Shared memory – represents (in Unix) the quickest form of communication between processes. There is a common virtual memory block shared between multiple processes. The processes are reading or writing in the common memory space using the same instructions used for reading/writing from/to the virtual memory. The permissions are read-only or read-write for each process. The mutual exclusion is assured by the processes that are using the shared memory.

Process concurrency in Unix/Linux Semaphores – represents a generalization of the system primitives wait and signal. The kernel is doing all the operations one by one and no process cannot access the semaphore till all operations are fulfilled. Signals – a signal is a software mechanism that informs a process about the appearance of an asynchronous event. A signal is similar with a hardware interrupt but it doesn’t implies priorities (all signals are considered “equal”). The signals that appear in the same time are presented to a process one by one, without an order based on priorities. The processes can send signals to other processes or the signals are sent by the kernel. A signal is delivered by updating a field in the (receiving) process table.

Read InformIT articles On InformIT you may find interesting articles from the IT field http://www.informit.com/articles/article.aspx?p=24972 http://www.informit.com/articles/article.aspx?p=1339466&seqNum=2