Starvation and Deadlock


Starvation and Deadlock are situations that occur when the processes that require a resource are delayed for a long time. However they are quite different concepts.

Details about starvation and deadlock are given as follows:

Starvation

Starvation occurs if a process is indefinitely postponed. This may happen if the process requires a resource for execution that it is never alloted or if the process is never provided the processor for some reason.

Some of the common causes of starvation are as follows:

  1. If a process is never provided the resources it requires for execution because of faulty resource allocation decisions, then starvation can occur.
  2. A lower priority process may wait forever if higher priority processes constantly monopolize the processor.
  3. Starvation may occur if there are not enough resources to provide to every process as required.
  4. If random selection of processes is used then a process may wait for a long time because of non-selection.

Some solutions that can be implemented in a system to handle starvation are as follows:

  1. An independent manager can be used for allocation of resources. This resource manager distributes resources fairly and tries to avoid starvation.
  2. Random selection of processes for resource allocation or processor allocation should be avoided as they encourage starvation.
  3. The priority scheme of resource allocation should include concepts such as aging, where the priority of a process is increased the longer it waits. This avoids starvation.

Deadlock

A deadlock occurs when two or more processes need some resource to complete their execution that is held by the other process.

Deadlock in OS

In the above diagram, the process 1 has resource 1 and needs to acquire resource 2. Similarly process 2 has resource 2 and needs to acquire resource 1. Process 1 and process 2 are in deadlock as each of them needs the other’s resource to complete their execution but neither of them is willing to relinquish their resources.

A deadlock will only occur if the four Coffman conditions hold true. These conditions are not necessarily mutually exclusive. They are given as follows:

  1. Mutual Exclusion
  2. Mutual exclusion implies there should be a resource that can only be held by one process at a time. This means that the resources should be non-sharable.

  3. Hold and Wait
  4. A process can hold multiple resources and still request more resources from other processes which are holding them.

  5. No preemption
  6. A resource cannot be preempted from a process by force. A process can only release a resource voluntarily.

  7. Circular wait
  8. A process is waiting for the resource held by the second process, which is waiting for the resource held by the third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular chain.

    raja
    Published on 10-Oct-2018 20:05:03
    Advertisements