Wa0018.
Wa0018.
SYSTEM
Submitted By: Jannat imtiaz
F2022105216
Malaika Zahra F2022105205
Section : Y-1
Submitted To : Sir Fahad Ali
Table of Contents
Introduction .................................................................................... 3
Objective ........................................................................................... 3
Purpose ............................................................................................. 3
Conclusion ..................................................................................... 11
• Introduction
Objective:
The object of this document is to define the concept of deadlock in
computer systems, where multiple processes fail to access the critical section
simultaneously or become stuck, and to explore strategies for preventing and
avoiding such situations.
Purpose:
The purpose of this document is to explain how deadlocks occur
when processes try to access critical sections simultaneously, leading to failure
or indefinite waiting. By understanding deadlock prevention and avoidance
strategies, readers can better design computer systems to ensure processes run
smoothly without being stuck forever, much like ensuring traffic flows through
intersections without gridlock.
• Deadlock Characteristics:
The deadlock has the following characteristics:
• Mutual Exclusion (Only one process can use a resource at a time)
• Hold and Wait (A process holds some resources while waiting for
others)
• No Preemption (Resources can’t be forcibly taken from a process,
the process must release them)
• Circular Wait ( Processes are stuck in a circle waiting for each other
in a loop)
• Deadlock Prevention :
We can prevent a Deadlock by
eliminating any of the above four conditions :
Eliminate No Preemption :
In simple terms:
In simple words, the process can only ask for resources in a forward direction
based on their numbers, which prevents the system from getting locked in a
cycle of waiting.
.
Process 1 is holding (assigned to) Resource 1 and waiting for Resource 2.
Process 2 is holding (assigned to) Resource 2 and waiting for Resource 1
• Deadlock Avoidance
Key Points:
This method is careful because it plans for the worst-case needs of processes.
While it prevents deadlocks, it might leave some resources unused to stay safe.
BANKER’S ALGORITHM
The Banker's Algorithm is a way to ensure that a computer system can safely
allocate resources to processes without running into a deadlock. It’s like a
banker managing loans to customers in a way that ensures the bank never runs
out of money.
Key Points:
1. Input Data:
o Total Resources: How many of each resource type the system has
(e.g., memory, CPUs).
o Maximum Need: The maximum number of resources each
process could request.
o Allocated: The resources currently given to each process.
o Available: Resources left after allocations.
2. Processes’ Requests:
o A process asks for resources.
o The system uses the algorithm to check if granting the request
keeps the system in a safe state (no risk of deadlock).
3. Safety Check:
o The system assumes it granted the resources and checks:
▪ Can each process finish its work using the resources it has
plus what's available?
o If yes, the state is safe, and the request is granted.
o If no, the state is unsafe, and the request is denied.
Advantages:
1. Avoids Deadlocks: Stops the system from getting stuck.
2. Uses Resources Well: Makes sure resources are given safely.
3. Fair: Makes sure no process waits forever.
4. Checks First: Tests if it’s safe before giving resources.
Disadvantages:
1. Needs Planning: You must know how many resources each process
might need.
2. Complicated: Hard to understand and set up.
3. Slow for Large Systems: Takes time if there are many processes.
4. May Waste Resources: Keeps some resources unused to stay safe.
Conclusion:
Deadlocks are critical situations in computer systems where processes get
stuck, unable to proceed due to resource contention. By understanding the
characteristics of deadlockscmutual exclusion, hold and wait, no
preemption, and circular waitcwe can implement strategies to prevent or
avoid them.