Javatpoint Logo
Javatpoint Logo

Difference between Deadlock and Starvation

Deadlock and starvation are conditions in which the processes requesting a resource have been delayed for a long time. However, deadlock and starvation are not the same things in many ways. Deadlock happens when every process holds a resource and waits for another process to hold another resource. In contrast, in starvation, the processes with high priorities continuously consume resources, preventing low priority processes from acquiring resources.

In this article, you will learn the difference between deadlock and starvation. But before discussing the difference between deadlock and starvation, you must need to learn about deadlock and starvation.

What is deadlock?

Deadlock happens when every process holds a resource and waits for another process to hold another resource. In other words, a deadlock occurs when multiple processes in the CPU compete for the limited number of resources available in the CPU. In this context, each process keeps a resource and waits for another process to obtain a resource.

Deadlock vs Starvation

Let's take an instance, Process (P1) is holding Resource (R1) and waiting for the Process (P2) to acquire the Resource (R2), and Process (P2) is waiting for the Resource (R1). Thus, Both the Process (P1) and (P2) is in a deadlock situation.

It is a common issue in multiprogramming OS, parallel computing systems, and distributed systems. There is a deadlock issue when one process requires a process that is requested by another process.

Four conditions may occur the condition of deadlock. These are as follows:

  1. Mutual Exclusion
  2. Hold and Wait
  3. No preemption
  4. Circular Wait

Mutual Exclusion

Only one process can utilize a resource at a time; if another process requests the same resource, it must wait until the process that is utilizing it releases it.

Hold and Wait

A process should be holding a resource when waiting for the acquirer of another process's resource.

No Preemption

The process holding the resources may not be preempted, and the process holding the resources should freely release the resource after it has finished its job.

Circular Wait

In a circular form, the process must wait for resources. Let's suppose there are three processes: P0, P1, and P2. P0 must wait for the resource held by P1; P1 must wait for process P2 to acquire the resource held by P2, and P2 must wait for P0 to acquire the process.

Although several applications may detect programs that are likely to become deadlocked, the operating system is never in charge of preventing deadlocks. It is the responsibility of programmers to create programs that are free of deadlocks, and it is possible to avoid deadlock by avoiding the conditions listed above.

What is Starvation?

Starvation happens when a low priority program requests a system resource but cannot run because a higher priority program has been employing that resource for a long time. When a process is ready to start executing, it waits for the CPU to allocate the necessary resources. However, because other processes continue to block the required resources, the process must wait indefinitely.

In most priority scheduling algorithms, the problem of starvation arises. The resource is frequently assigned to the higher priority process in a priority scheduling method, which helps to prevent the lower priority process from obtaining the requested resource.

Starvation is an issue that can be solved through aging. Aging raises the priority of a procedure that has been waiting for resources for a long period. It also helps to prevent a low-priority procedure from waiting indefinitely for resources.

There are some common causes of starvation as follows:

  1. Starvation may occur if there aren't enough resources to provide to every process as needed.
  2. Starvation can occur if a process is never given the resources it needs for execution due to faulty resource allocation decisions.
  3. If higher priority operations constantly monopolize the processor, a lower priority process may have to wait indefinitely.

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

  1. The resource allocation priority scheme should contain concepts such as aging, in which the priority of a process increases the longer it waits. It prevents starvation.
  2. An independent manager may be used for the allocation of resources. This resource manager distributes resources properly and tries to prevent starvation.
  3. Random process selection for resource allocation or processor allocation should be avoided since it promotes starvation.

Main differences between the deadlock and starvation

Here, you will learn the main differences between deadlock and starvation. Various differences between deadlock and starvation are as follows:

  1. Deadlock happens when every process holds a resource and waits for another process to hold another resource. In contrast, starvation happens when a low priority program requests a system resource but cannot run because a higher priority program has been employing that resource for a long time.
  2. In a deadlock, none of the processes can proceed to execution; instead, each process is blocked while waiting for resources to be acquired by another process. On the other hand, starvation is a situation in which higher-priority processes have an infinite ability to acquire resources. Moreover, lower-priority processes are prevented from getting resources, resulting in their indefinite blocking.
  3. Deadlock happens when four conditions exist simultaneously: mutual exclusion, hold and wait, no preemption, and circular wait. In contrast, starvation happens when process priorities are enforced while distributing resources or when resource management is unmanaged.
  4. In a deadlock situation, the process blocks resources. In contrast, high-priority processes continue to use the requested resources in starvation.
  5. Deadlock is also known as circular wait, whereas starvation is known as a Lived lock.

Head-to-head comparison between the deadlock and starvation

Deadlock vs Starvation

Here, you will learn the head-to-head comparison between deadlock and starvation. Various head-to-head comparisons between deadlock and starvation are as follows:

Features Deadlock Starvation
Definition Deadlock happens when every process holds a resource and waits for another process to hold another resource. Starvation happens when a low priority program requests a system resource but cannot run because a higher priority program has been employing that resource for a long time.
Basic A deadlock occurs when no process can proceed and becomes blocked. Starvation occurs when low priority procedures are blocked while high priority operations proceed.
Other names Deadlock is also known as circular wait. Starvation is known as a Lived lock.
Resources Other processes block requested resources while a process is deadlocked. High-priority processes continue to use the requested resources.
Arising Condition Mutual exclusion's occurrence, Hold and wait, No preemption, and Circular wait all happen simultaneously. Uncontrolled resource management, enforcement of priorities.
Prevention It can be prevented by avoiding the situations that lead to deadlock. Aging may prevent it.

Conclusion

Multiple processes are executing in an operating system. Both starvation and deadlock are two methods that may happen when there are processes. Deadlock happens when every process holds a resource and waits to obtain a resource held by another process. In contrast, starvation happens when a process waits indefinitely for a required resource. Deadlock may cause processes to starvation, and on the other side, starvation can break the deadlock.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA