Osy Micro (Eshwar)
Osy Micro (Eshwar)
PROJECT REPORT
ON
“DEADLOCK”
SUBMITTED BY
Mr. Malshikare Eshwar D. [148]
[1]
Sanjivani Rural Education Society’s SANJIVANI K. B. P.
POLLYTEHNIC
DEPARTMENT OF COMPUTER TECHNOLOGY
CERTIFICATE
This is to certify that the Project report entitled
“DEADLOCK”
Submitted by
Mr. Malshikare Eshwar D. [148]
Under our supervision and guidance for partial fulfilment of the
requirement for
DIPLOMA IN COMPTUTER TECHNOLOGY affiliated to
Maharashtra State Board of Technical Education, Mumbai For
academic year
2024-2025.
[2]
Index
1. Introduction 4
3. Deadlock Prevention 6
4. Deadlock Avoidance 8
5. Conclusion
[3]
INTRODUCTION
In an operating system (OS), a deadlock is a situation where a set of processes are
unable to proceed because each is waiting for a resource that is being held by
another process in the set. As a result, none of the processes can complete, leading
to a system halt or a frozen state. Deadlock typically occurs in multi-tasking or
multi- threaded environments when processes compete for system resources such
as memory, CPU time, or input/output devices.
What is Deadlock?
Deadlock is a situation in computing where two or more processes are unable to
proceed because each is waiting for the other to release resources. Key concepts
include mutual exclusion, resource holding, circular wait, and no pre-emption.
Consider an example when two trains are coming toward each other on the same
track and there is only one track, none of the trains can move once they are in front
of each other. This is a practical example of deadlock.
[4]
Necessary conditions for Deadlocks
1. Mutual Exclusion: A resource can only be shared in mutually exclusive
manner. It implies, if two processes cannot use the same resource at the
same time. At least one resource must be head in a non-sharable mode that is
only one process at a time use the resources.
If another process request that resources the requesting process must be delay
until the process has been released.
2. Hold and Wait: A process waits for some resources while holding another
resource at the same time.
There must exit a process that is holding atleast one resource and is waiting to
aquire additional resource that are currently being held by other process.
3. No pre-emption: The process which once scheduled will be executed till
the completion. No other process can be scheduled by the scheduler
meanwhile.
4. Circular Wait: All the processes must be waiting for the resources in a
cyclic manner so that the last process is waiting for the resource which is
being held by the first process.
Deadlock Recovery
Deadlock Ignorance
[5]
Deadlock Prevention
In deadlock prevention the aim is to not let full-fill one of the required condition of
the deadlock. This can be done by this method:
We only use the Lock for the non-share-able resources and if the resource is share-
able (like read only file) then we not use the locks here. That ensure that in case of
share -able resource, multiple process can access it at same time. Problem- Here
the problem is that we can only do it in case of share-able resources but in case of
no- share-able resources like printer, we have to use Mutual exclusion.
To ensure that Hold and wait never occurs in the system, we must guarantee that
whenever process request for resource, it does not hold any other resources.
we can provide the all resources to the process that is required for its
execution before starting its execution. problem – for example if there are
three resource that is required by a process and we have given all that
resource before starting execution of process then there might be a situation
that initially we required only two resource and after one hour we want third
resources and this will cause starvation for another process that wants these
resources and in that waiting time that resource can allocated to other
process and complete their execution.
We can ensure that when a process request for any resources that time the
process does not hold any other resources. Ex- Let there are three resources
DVD, File and Printer. First the process request for DVD and File for the
copying data into the file and let suppose it is going to take 1 hour and after
it the process free all resources then again request for File and Printer to
print that file.
[6]
(iii) No Pre-emption
If a process is holding some resource and requestion other resources that are
acquired and these resources are not available immediately then the resources that
current process is holding are pre-empted. After some time, process again request
for the old resources and other required resources to re-start.
Each resource will be assign a numerical number, a process can request the
resource to increasing order numbering.
Example:-If the P1 process is allocated R1 resource next time if P1 ask for R2 such
as the requesting resource will not be lessor than R1 and request will not be
granter. Only the request for resource more than R1 will granted.
[7]
Deadlock Avoidance
Avoidance is kind of futuristic. By using the strategy of “Avoidance”, we have to
make an assumption. We need to ensure that all information about resources that
the process will need is known to us before the execution of the process. We use
Banker’s algorithm (Which is in turn a gift from Dijkstra) to avoid deadlock.
Banker’s Algorithm
The Banker’s Algorithm is a resource allocation and deadlock avoidance algorithm
that tests for safety by simulating the allocation for the predetermined maximum
possible amounts of all resources, then makes an “s-state” check to test for possible
activities, before deciding whether allocation should be allowed to continue.
The Banker’s Algorithm is a smart way for computer systems to manage how
programs use resources, like memory or CPU time. It helps prevent situations
where programs get stuck and can’t finish their tasks, which is called deadlock. By
keeping track of what resources each program needs and what’s available, the
algorithm makes sure that programs only get what they need in a safe order. This
helps computers run smoothly and efficiently, especially when lots of programs are
running at the same time.
[8]
Deadlock Recovery
If Deadlock prevention or avoidance is not applied to the software then we can
handle this by deadlock detection and recovery. which consist of two phases:
1. In the first phase, we examine the state of the process and check whether
there is a deadlock or not in the system.
2. If found deadlock in the first phase then we apply the algorithm for
recovery of the deadlock.
In Deadlock detection and recovery, we get the correctness of data but performance
decreases.
Manual Intervention
Automatic Recovery
Process Termination
Resource Preemption
Example of Deadlock
Imagine two processes, Process A and Process B, and two resources, Resource X
and Resource Y. The deadlock can occur in the following sequence:
[9]
Conclusion
Reference
https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.geeksforgeeks.o
rg/introduction-of-deadlock-in-operating-
system/&ved=2ahUKEwiThczpkaWJAxVqh1YBHYkfCEgQFnoECBkQAQ&usg=AOvVaw3rIjah5M6v
JG5Zq_kepdBb
https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.scaler.com/topic
s/operating-system/deadlock-in-
os/&ved=2ahUKEwiThczpkaWJAxVqh1YBHYkfCEgQFnoECEEQAQ&usg=AOvVaw1xZLcAqwA4a
M_Kiu0SXCMK
[10]
[11]