The main difference between deadlock and starvation is that deadlock occurs when each process holds a resource and waits to obtain a resource held by another process while starvation occurs when a process waits for an indefinite period of time to obtain a required resource.
A computer system performs multiple processes simultaneously. A process loads to memory at the time of execution. Processes are created and terminated continuously. The operating system maintains a Process Control Block (PCB) for each process. PCB includes information such as process id, program counter, memory management information and many more. The operating system deletes the PCB after the process terminates. Deadlock and starvation are two situations that are related to processes.
Key Areas Covered
1. What is Deadlock
– Definition, Functionality
2. What is Starvation
– Definition, Functionality
3. Difference Between Deadlock and Starvation
– Comparison of Key Differences
Key Terms
Deadlock, Process, Operating System, Starvation
What is Deadlock
A process is a program in execution. It requires various resources while executing. First, the process requests a resource. After obtaining the resource, it uses it and releases the resource. For example, assume there is a set of processes. Each process holds a resource and waits to get a resource that is held by another process. We call this kind of situation a deadlock.
A deadlock can occur when the following conditions happen simultaneously.
Mutual Exclusion – Only one process can use a resource at a time.
Hold and Wait – A process that holds at least one resource is waiting to acquire additional resources held by other processes.
No Preemption – A resource is released by the process holding it after completing the task.
Circular Wait – Assume that there are four processes called P1, P2, P3, and P4. P1 is waiting for a resource held by P2. P2 is waiting for a resource held by P3. P3 is waiting for a resource held by P4 and P4 is waiting for a process held by P1. We call this kind of situation a circular wait.
Given below are some mechanisms to eliminate a deadlock after it has occurred:
Preemption – Obtain a resource from a process and allocate it to another.
Rollback – When a deadlock occurs, roll everything to the last safe state and allocate the resources differently to avoid a deadlock situation.
Additionally, it is also possible to terminate single or multiple processes. But, this is an expensive method.
What is Starvation
Starvation is a situation that occurs when a process waits for a resource for a longer period of time. Processes have priorities. High priority processes get the required resources within minimum time. However, this causes low priority processes to wait for the required processes to complete the task. When these processes wait for an infinite amount of time, we call it starvation of resource starvation.
Furthermore, a solution to overcome starvation is aging. This technique gradually increases the priority of processes that wait in the system for a long time. When the priority increases the process can obtain the required resources.
Difference Between Deadlock and Starvation
Definition
Deadlock is a situation that occurs with a set of processes in which every process is waiting for an event that can only be caused by another process in the set. Starvation, on the other hand, is a situation in which a process is perpetually denied necessary resources to process its work. Thus, this is the main difference between Deadlock and Starvation.
Occurs
Deadlock occurs when each process is holding a resource and waits for a resource held by another process while starvation occurs when a process waits for a resource for a long period of time.
Proceeding
In a deadlock situation, all the related processes cannot proceed. However, in starvation, only some processes wait for resources, but others can proceed. Hence, this is also a difference between Deadlock and Starvation.
Conclusion
There are multiple processes running in an operating system. Deadlock and starvation are two situations that can occur when there are processes. The main difference between deadlock and starvation is that deadlock occurs when each process holds a resource and waits to obtain a resource held by another process while starvation occurs when a process waits for an indefinite period of time to obtain a required resource.
References:
1. “What Is a Deadlock?” Studytonight, Available here.
2. “Operating System | Starvation and Aging in Operating Systems.” GeeksforGeeks, 9 Feb. 2018, Available here.
3. “Starvation (Computer Science).” Wikipedia, Wikimedia Foundation, 15 Dec. 2018, Available here.
Image Courtesy:
1.”Deadlock” By Niqueco – Own work (CC0) via Commons Wikimedia
Leave a Reply