deadlock

48
Jawad Shafi [email protected] Assistant Professor CS COMSATS Institute of Information Technology, Lahore

Upload: sohaib-khan

Post on 08-Nov-2015

217 views

Category:

Documents


0 download

DESCRIPTION

Operating System

TRANSCRIPT

  • Jawad [email protected] Professor CSCOMSATS Institute of Information Technology, Lahore

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • Operating System Concepts

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • Operating System Concepts

  • Operating System Concepts

  • Operating System Concepts

  • Operating System Concepts

  • Operating System Concepts

  • Operating System Concepts

  • Draw a resource-allocation graphThe sets P, R, and E:Operating System Concepts

  • Resource instances:

    One instance of resource type R1Two instances of resource type R2One instance of resource type R3Three instances of resource type R4Operating System Concepts

  • Operating System Concepts

  • Operating System Concepts

  • Deadlock preventionis a set of methods for ensuring that at least one of the necessary conditions (Slide 7) cannot hold.Operating System Concepts

  • Operating System Concepts

  • Mutual ExclusionThe mutual-exclusion condition must hold for nonsharable resources. For example, a printer cannot be simultaneously shared by several processes. Sharable resources, on the other hand, do not require mutually exclusive access, and thus cannot be involved in a deadlock. Read-only files are a good example of a sharable resource. If several processes attempt to open a read-only file at the same time, they can be granted simultaneous access to the file. A process never needs to wait for a sharable resource.Operating System Concepts

  • Operating System Concepts

  • Deadlock avoidanceon the other hand, requires that the operating systembe given in advance additional information concerning which resources a process will request and use during its lifetime.Operating System Concepts

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • *Computer Science Department- CIIT*

  • Possible states areDeadlock No forward progress can be made. Unsafe state A state that may allow deadlock. Safe state A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish.Operating System Concepts

  • Page 254_To illustrate, we consider a system with 12 magnetic tape drives and 3 processes: Po, PI, and P2. Process Po requires 10 tape drives, process PI may need as many as 4, and process P2 may need up to 9 tape drives. Suppose that, at time to, process Po is holding 5 tape drives, process PI is holding 2, and process PZ is holding 2 tape drives. (Thus, there are 3 free tape drives.)Operating System Concepts

  • Operating System ConceptsAt time to, the system is in a safe state. The sequence satisfies the safety condition, since process PI can immediately be allocated all its tape drives and then return them (the system will then have 5 available tape drives), then process Po can get all its tape drives and return them (the system will then have 10 available tape drives), and finally process P2 could get all its tape drives and return them (the system will then have all 12 tape drives available).

  • A system may go from a safe state to an unsafe state. Suppose that, at time tl, process P2 requests and is allocated 1 more tape drive. The system is no longer in a safe state. At this point, only process PI can be allocated all its tape drives. When it returns them, the system will have only 4 available tape drives. Since process Po is allocated 5 tape drives, but has a maximum of 10, it may then request 5 more tape drives. Since they are unavailable, process Po must wait. Similarly, process P2 may request an additional 6 tape drives and have to wait, resulting in a deadlock.Operating System Concepts

  • Our mistake was in granting the request from process P2 for 1 more tape drive. If we had made P2 wait until either of the other processes had finished and released its resources, then we could have avoided the deadlock.Operating System Concepts

  • Page 273Operating System Concepts

  • *Computer Science Department- CIIT*

  • *Ciit, Deft of CS-LHR

  • Operating System Concepts

  • Operating System Concepts

  • Operating System ConceptsConsider a computer system that runs 5,000 jobs per month with no deadlock-prevention or deadlock-avoidance scheme. Deadlocks occur about twice per month, and the operator must terminate and rerun about 10 jobs per deadlock. Each job is worth about $2 (in CPU time), and the jobs terminated tend to be about half-done when they are aborted. A systems programmer has estimated that a deadlock-avoidance algorithm (like the bankers algorithm) could be installed in the system with an increase in the average execution time per job of about 10 percent. Since the machine currently has 30-percent idle time, all 5,000 jobs per month could still be run, although turnaround time would increase by about 20 percent on average.

  • a. What are the arguments for installing the deadlock-avoidance algorithm? b. What are the arguments against installing the deadlock-avoidance algorithm?

    Operating System Concepts

  • An argument for installing deadlock avoidance in the system is that we could ensure dead lock would never occur. In addition, despite the increase in turnaround time, all 5,000 jobs could still run. An argument against installing deadlock avoidance software is that deadlocks occur infrequently and they cost little when they do occur.Operating System Concepts

  • We have 5 processes, i.e., P0 through P4, and 3 resource types: A (10 instances), B (5 instances), and C (7 instances). The snapshot of the system at time T0 is Allocation Max AvailableA B C A B C A B C

    P0 0 1 07 5 3 3 3 2P12 0 0 3 2 2P2 3 0 2 9 0 2P32 1 1 2 2 2P4 0 0 2 4 3 3

    Operating System Concepts

  • Can request for (1, 2, 3) by P0 be granted? If yes, what will be the sequence?Can request for (1, 0, 2) by P0 be granted? If yes, what will be the sequence?Can request for (0, 3, 0) by P0 be granted? If yes, what will be the sequence?Operating System Concepts

  • (1, 2, 3) cannot be granted because it is greater than the available resources. Yes, it can be granted by the sequence (0, 3, 0) cannot be granted because the available will then become (3, 0, 2) which cannot satisfy any other requestOperating System Concepts

  • Consider the scenario below and justify whether there is a deadlock or not.Operating System Concepts

  • No deadlock, becauseR1 is allocated to P2, which is not part of the cycle. Also R2 is allocated to P4, which is not part of the cycle.so once the resources are released by P2 and/or P4, they can be allocated to P1 and P3.Operating System Concepts

  • Questions ???Operating System Concepts