Friday, 26 April 2013

What is deadlock in operating system and its prevention methods

deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does.

What is a deadlock in operating system? Is it a state where two ore more operations are waiting for each other, say a computing action 'A' is waiting for action 'B' to complete, while action 'B' can only execute when 'A' is completed. Such a situation would be called a deadlock. In operating systems, a deadlock situation is arrived when computer resources required for complete of a computing task are held by another task that is waiting to execute. The system thus goes into an indefinite loop resulting into a deadlock.

The deadlock in operating system seems to be a common issue in multiprocessor systems, parallel and distributed computing setups.


gridlock

In order for deadlock to occur, four conditions must be true.
  • Mutual exclusion - Each resource is either currently allocated to exactly one process or it is available. (Two processes cannot simultaneously control the same resource or be in their critical section).
  • Hold and Wait - processes currently holding resources can request new resources
  • No preemption - Once a process holds a resource, it cannot be taken away by another process or the kernel.
  • Circular wait - Each process is waiting to obtain a resource which is held by another process.
    a process A needs some resource R1 which is acquired by some other process B,and process B needed some resource R2 ,which is acquired by process A.Hence none of the process acquired the required resource as both the respective process are in waiting condition and hence deadlock occurs.

    [IMG]

    Just think of a real time scenario

    A situation when brother are fighting for playing video game 

    One brother has remote control for playing and other has game cd or whaever we call 

    No only one person can play but both are not ready to cooperate and hence it results in deadlock, no one can play now, same is with operating system

    I hope this is very simple example to get a clear idea of deadlock.

    Methods for Handling Deadlocks:

    Ensure that the system will never enter a deadlock state.
    Allow the system to enter a deadlock state and then recover.
    Ignore the problem and pretend that deadlocks never  occur in the system; used by most operating systems, including UNIX.


    Deadlock Prevention:

    Mutual Exclusion – not required for sharable resources; must hold for non-sharable resources.

    Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources.
    Require process to request and be allocated all its  sources before it begins execution, or allow process to request resources only when the process has none. Low resource utilization; starvation possible. Restrain the ways request can be made.

    No Preemption –  If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.
    Preempted resources are added to the list of resources for which the process is waiting.
    Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.

    Circular Wait – impose a total ordering of all resource types, and require that each process requests resources  in an increasing order of enumeration           

No comments:

Post a Comment