Table of contents
1.
Introduction
2.
What is Deadlock?
2.1.
Mutual exclusion 
2.2.
Hold and Wait
2.3.
No Preemption
2.4.
Circular wait
3.
What is Starvation?
4.
Difference Between Deadlock and Starvation
5.
 
6.
 
7.
 
7.1.
Frequently Asked Questions
7.2.
Why is deadlock more critical than starvation?
7.3.
What is a real-life example of deadlock starvation?
7.4.
Can you have a deadlock without starvation?
7.5.
Conclusion
Last Updated: Jul 3, 2024
Easy

Difference between Deadlock and Starvation

Author Divyansh Jain
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Difference between Deadlock  and Starvation

Introduction

Deadlock is a situation when all processes are holding one resource each while they wait for another process to acquire a different resource. Starvation is a situation that prevents low-priority processes from acquiring resources. Starvation occurs when processes with high priorities constantly consume resources.

To begin with, we all know how important the role of operations between processes has in any operating system.

A computer system can handle numerous tasks at once. At the moment of execution, a process loads into memory. Processes are continually produced and destroyed. Deadlock and starvation are two common issues that are attributed to processes.

So, to understand the difference between the two, we have to first understand both the terms in detail. Are you excited to dive into the deep concepts of operating systems? So, let’s get started.

Also see, Types of Operating Systems and Open Source Operating System.

What is Deadlock?

Whenever a process enters a waiting state since the other waiting process is holding the requested resource, it is called a deadlock. A major difficulty in multi-processing is a deadlock, which occurs when numerous processes share a mutually exclusive resource known as a soft lock or software.

What is Deadlock

To understand more, let’s take a real-life example of running traffic, which only moves in one way. And, a bridge is a resource in this case. So, In this situation, we can see that the problem can be solved if one car backs up or a process backs up in the operating system. When a deadlock occurs, it is readily resolved when we Preempt resources and rollback.

So, did u get the concept or not? As it was more about the real world and less about the computer world, so let us take a much more brief and more relatable example that directly relates to the operating processes.

So, Let's assume that P1 and P2 are the two processes we have. Process P1 is currently holding resource R1 and waiting for resource R2. And, at the very same time, process P2 is using resource R2 while waiting for resource R1.

Deadlock Resources

As a result, process P1 is waiting for process P2 to give up its resource while process P2 is also waiting for process P1 to free its resource. And no resources are being released. As a result, they are each waiting for the other to relinquish the resource. This results in endless waiting and no work being done. This is known as deadlock.

Below are the four conditions that may occur in deadlock. These are as follows:

  • Mutual Exclusion
  • Hold and Wait
  • No preemption
  • Circular Wait

Mutual exclusion 

If another process requests the same resource, it must wait until the resource is released by the process that is now using it.

Hold and Wait

A process must be holding a resource while awaiting the acquisition of another resource held by another process.

No Preemption

The resource-holding process cannot be stopped or preempted. When the process holding the resource has completed its duty, it must relinquish the resource willingly.

Circular wait

In a cyclical form, the process must wait for resources. Assume there are three processes: P0, P1, and P2. P0 must wait for the resource owned 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.

Now, let us discuss Starvation in detail: 

What is Starvation?

When a process waits for a resource for an extended length of time, it is called starvation. Priorities exist in processes. High-priority processes receive resources in a timely manner. Low-priority processes, on the other hand, must wait for the essential processes to finish the task. We call it starvation of resource starvation when these processes wait for an endless length of time.

In a densely loaded system of computers, a continual stream of varied higher-priority activities can keep all low-priority processes from ever reaching the CPU.
When there is a scarcity of resources, the high-priority processes use them all. The problem of starvation may be simply solved with the concept of Aging. All of the long waiting processes become more important as they become older.

This can happen when a method requires a resource that hasn't been assigned.

These resources include the following:

  • Disk space
  • CPU time
  • Memory
  • I/O access to network or disk
  • network bandwidth
     

When low-priority processes get clogged for an unknown period of time while high-priority processes continue to run, a continual stream of higher-priority methods will prevent a low-priority process from gaining access to the CPU

Starvation Example

In the example above, process P2 has the greatest priority, whereas process P1 has the lowest. We have a number of processes that are ready to be executed in general. As time passes, if only those processes that have a higher priority than the process P1 enter the CPU, the process P1 will continue to wait for its turn for CPU allocation and will never receive it because all the other processes have a higher priority than P1. This is referred to as starvation.

As a result, starvation should be eliminated since if a process is ready, we should allocate a CPU to it. We may take our time allocating the CPU to the process because it is a low priority, but we must guarantee that the CPU is allocated.

And, now we are very clear with the two concepts, so it’s time to understand the difference between them. So, let’s get going! 

Difference Between Deadlock and Starvation

The following are the differences between Deadlock and Starvation.

Basis

DEADLOCK

STARVATION

Definition

When two or more processes require some resources to finish the execution held by the other process, a deadlock arises. When a process demands a resource for execution that is never available, it is called starvation.

Type Of Issue

Deadlock is more of a distributed design or better say process design concern. Starvation is more of a scheduling problem.

Also called

Circular wait. Lifelock.

Prevention

Allowing preemption and preventing mutual exclusion, circular wait, and hold and wait. We may simply avoid starvation by using the concept of Aging.

Supplies

Requested supplies are blocked by other processes in a deadlock. When supplies are scarce, high-priority processes consume them continually.

Emerging Condition

No Preemption, Hold and Wait for Circular Wait, and Mutual Exclusion are all required factors. Conditions like Prioritization enforcement and unregulated resource management.

 

 

 

Also see, AMD vs Intel

Frequently Asked Questions

Why is deadlock more critical than starvation?

Deadlock is more critical than starvation because it halts the entire system, requiring complex intervention to resolve, whereas starvation affects individual processes, allowing the system to continue operating and can often be mitigated with fair scheduling policies.

What is a real-life example of deadlock starvation?

The decision to wait at the crosswalk, the amount of time spent waiting for a lift to reach a floor that causes starvation, and overfeeding fish that results in an unexpected situation are real-world examples of deadlock starvation.

Can you have a deadlock without starvation?

Starvation might happen as a result of a deadlock, a livelock, or another process. So we can say that every starvation is a deadlock but this is not true for the deadlock. We can have a deadlock without starvation.

Conclusion

So, we understood that by blocking the process, both Deadlock and Starvation slow it down. On the one hand, a deadlock can cause processes to starve, while on the other hand, a deadlock can cause processes to starve. We discussed both deadlock and starvation in detail and then we talked about the major differences between them. Also, we interrogated some frequent doubts regarding the domain.

Hope you learned something. But the knowledge never stops, So to learn more you can visit our website for more articles. 

Recommended Readings: 


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Do upvote our blog to help other ninjas grow.

Happy Learning Ninja :) 

Live masterclass