Question:

Could anyone tell me how to avoid deadlock or atleast how to detect and kill deadlock?

by  |  earlier

0 LIKES UnLike

Could anyone tell me how to avoid deadlock or atleast how to detect and kill deadlock?

 Tags:

   Report

4 ANSWERS


  1. Your question is not clear

    Deadlock in what or when?


  2. Hi Arun!

    Its good to avoid the deadlock rather than to solve it later.the best way is don't try to generate the simultaneously request for one resource at a time.you sholud've to be careful when a resource is in network then always execute ur request with high priority rule or round robin or in the queue rule.

    Avoid actions that may lead to a deadlock.

    Think of it as a state machine moving from 1 state to another as each instruction is executed.

    Safe State

    Safe state is one where

        * It is not a deadlocked state

        * There is some sequence by which all requests can be satisfied.

    To avoid deadlocks, we try to make only those transitions that will take you from one safe state to another. We avoid transitions to unsafe state (a state that is not deadlocked, and is not safe)

    nd for

        *

              o

                Detection and Recovery

                Is there a deadlock currently?

                One resource of each type (1 printer, 1 plotter, 1 terminal etc.)

                    + check if there is a cycle in the resource graph. for each node N in the graph do DFS (depth first search) of the graph with N as the root In the DFS if you come back to a node already traversed, then there is a cycle. }

                Multiple resources of each type

                    + m resources, n processes

                    + Max resources in existence = [E1, E2, E3, .... Em]

                    + Current Allocation = C1-n,1-m

                    + Resources currently Available = [A1, A2, ... Am]

                    + Request matrix = R1-n,1-m

                    + Invariant = Sum(Cij) + Aj = Ej

                    + Define A <= B for 2 vectors, A and B, if Ai <= Bi for all i

                    + Overview of deadlock detection algorithm,

                      Check R matrix, and find a row i such at Ri < A.

                      If such a process is found, add Ci to A and remove process i from the system.

                      Keep doing this till either you have removed all processes, or you cannot remove any other process.

                      Whatever is remaining is deadlocked.

                      Basic idea, is that there is atleast 1 execution which will undeadlock the system

                Recovery

                    + through preemption

                    + rollback

                          # keep checkpointing periodically

                          # when a deadlock is detected, see which resource is needed.

                          # Take away the resource from the process currently having it.

                          # Later on, you can restart this process from a check pointed state where it may need to reacquire the resource.

                    + killing processes

                          # where possible, kill a process that can be rerun from the beginning without illeffects

  3. When two users try to update same row of a table at same time the deadlock occurs (When auto commit is off). To kill it you have to Commit/Rollback one of the transactions.

  4. http://en.wikipedia.org/wiki/Deadlock

    This article on Wikipedia has many useful topics on it such as prevention.

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.