- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
- If a process is never provided the resources it requires for execution because of faulty resource allocation decisions, then starvation can occur.
- A lower priority process may wait forever if higher priority processes constantly monopolize the processor.
- Starvation may occur if there are not enough resources to provide to every process as required.
- 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 −
- An independent manager can be used for allocation of resources. This resource manager distributes resources fairly and tries to avoid starvation.
- Random selection of processes for resource allocation or processor allocation should be avoided as they encourage starvation.
- 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.
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 −
- Mutual Exclusion
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.
- Hold and Wait
A process can hold multiple resources and still request more resources from other processes which are holding them.
- No preemption
A resource cannot be preempted from a process by force. A process can only release a resource voluntarily.
- Circular wait
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.
- Related Articles
- Deadlock, Starvation & LiveLock
- Deadlock and Starvation in C#
- Difference Between Deadlock and Starvation in OS
- Difference between Deadlock Prevention and Deadlock Avoidance
- Deadlock Detection and Recovery
- Deadlock Characterization
- Deadlock Avoidance
- Deadlock Prevention
- Deadlock System Model
- Deadlock in Java Multithreading
- Deadlock with mutex locks
- Error codes, cause and example of deadlock in DB2
- Deadlock and Default Case in Select Statement in Golang
- Deadlock ignorance in Operating system
- Display all deadlock logs in MySQL?
