Introdution

  • Generally, file resources when shared as read-only, never lead to deadlock condition.

Definition

  • The deadlock is a situation of an operating system in which no process is blocked and no process proceeds.
  • A deadlock is a situation where each of the computer processes waits for a resource that is being assigned to/used by another process at the same time. In this situation, none of the processes get executed since the resource they need is held by another process that is also waiting for some other resource to be released.
  • In simple words, a deadlock in an operating system is a situation where two or more processes get stuck because each is waiting for a resource that the other has. As a result, none of them can continue, and they are blocked forever.

Characteristics

  • Deadlock is an infinite process.
  • A deadlock is a situation that typically occurs in a multitasking or multiprocessor operating system where several processes share a specific type of mutually exclusive resource.
  • Every deadlock shows a starvation situation.

Examples

  • Example 1: 
    • Process A holds Resource 1, and needs Resource 2.
    • Process B holds Resource 2, and needs Resource 1.
    • Both wait forever — deadlock.
  • Example 2 :

    • Suppose Process 1 holds/uses the printer, waiting(wants to use) for the scanner.
    • Process 2 holds the scanner, waiting for the printer.
    • Both wait forever and are stuck. This is a deadlock.
  • Example 3 :

Thus, if processes don’t release the resources and keep waiting for each other, a deadlock happens.

Conditions for Deadlock (Coffman’s Conditions)

There are four typical or necessary conditions for deadlock. These are –

  • Mutual Exclusion(Mutex) :
    • It is a special type of binary semaphore that is used for controlling access to the shared resource.
    • It assures that a resource can only be shared in a mutually exclusive manner to avoid deadlock, i.e., two or more processes cannot use the same resource at the same time.
    • It assures that only one process can use a resource at a time.
  • Hold and Wait :
    • This principle says that a process is holding one resource and waiting for another if needed, i.e., in this method, generally a process waits for some resources (that it wants to use further)while holding and using another resource at the same time.
  • No preemption : 
    • In this method, the process, once scheduled, will be executed till completion. At that time, no other related processes can be scheduled by the scheduler, i.e., resources used cannot be forcibly taken.
  • Circular Wait :
    • All the processes in the process queue must be waiting for the resources in a cyclic manner so that the last process is waiting for the resource that is being held by the first process, and so on.
    • In other words, circular wait is a situation in which one process is waiting for the resource, which is held/used by the second process, which is also waiting for the resource held/used by the third process, and so on. This will continue until the last process is waiting for a resource held/used by the first process. This constitutes a circular chain and finally a circular wait condition. Finally, we can say that it is a closed chain of processes, each waiting on a resource from the next

Advantages

  • Deadlock itself is not an advantage — it’s a problem in operating systems and programming, even then, it has some advantages-
    • To run an operating system smoothly.
    • Better Resource Utilization

Disadvantages/Demerits

  • It delays process initiation.
  • It freezes the system or slows it down.
  • It wastes memory and processing power.
  • It may require manual intervention to solve.

Handling of Deadlock

There are following ways to handle a deadlock situation in an os –

(a) Deadlock Ignorance :
  • In simple case, deadlock Ignorance is the most widely used approach among all the mechanism by many operating systems mainly for end user uses.
  • In this approach, the operating system assumes that deadlock never occurs or ignorable.
  • This approach is best suitable for a single end user system where User uses the system only for browsing and all other normal work.
  • To get rid of simple ignorable deadlock, the user may simply restart the computer system . 
(b) Deadlock Detection & Recovery :
  • A deadlock detection is a method to find out whether deadlock occurred in an operating system or not.
  • This is done by checking the status of the resource scheduler that helps OS to keep track of all the resources which are allocated to different processes during execution time. If single resource is allocated/used/shared by single process at a time then deadlock did not occur.
  • When a deadlock is detected in a system then it applies some of the recovery methods to the system to get rid of deadlock.
(c) Deadlock Prevention :
  • Deadlock prevention is a method to do all those related activities that try to remove deadlock situation after it occurrence.
  • It is better to prevent a deadlock before it can occur.
  • In this method, the system checks every process (with its allocated resource) before it is executed to make sure that it wouldn’t lead the deadlock situations.
  • In deadlock prevention, all the four conditions for deadlock is checked and managed.
(d) Deadlock Avoidance :
  • Deadlock avoidance is a precautionary/earlier method to do all those related activities that try to prevent deadlock situation before it occurrence.
  • It is better to avoid a deadlock instead of taking action after the deadlock has occurred. 
  • Deadlock avoidance is the simplest and most useful model that each process declares the maximum number of resources of each type that it may need.

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.