0% found this document useful (0 votes)
12 views9 pages

Wa0018.

This document defines deadlock in computer systems and explores strategies for its prevention and avoidance, including the characteristics of deadlock such as mutual exclusion and circular wait. It discusses deadlock prevention methods that eliminate conditions leading to deadlock and introduces the Banker's Algorithm for deadlock avoidance, highlighting its advantages and disadvantages. The conclusion emphasizes the importance of understanding deadlocks to ensure efficient and smooth operation of computer systems.

Uploaded by

jannatimtiaz288
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

Wa0018.

This document defines deadlock in computer systems and explores strategies for its prevention and avoidance, including the characteristics of deadlock such as mutual exclusion and circular wait. It discusses deadlock prevention methods that eliminate conditions leading to deadlock and introduces the Banker's Algorithm for deadlock avoidance, highlighting its advantages and disadvantages. The conclusion emphasizes the importance of understanding deadlocks to ensure efficient and smooth operation of computer systems.

Uploaded by

jannatimtiaz288
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

OPERATING

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

Deadlock Characteristics ................................................................. 4


Mutual Exclusion .............................................................................. 4
Hold and Wait ................................................................................... 4
No Preemption ................................................................................. 4
Circular Wait...................................................................................... 4

Deadlock Prevention ....................................................................... 4


Deadlock Avoidance ............................................................................ 6

Banker’s Algorithm .............................................................................. 7


Introduction ....................................................................................... 7
Advantages ........................................................................................ 8
Disadvantages .................................................................................... 9

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 Mutual Exclusion:


Mutual exclusion means some resources can
only be used by one process at a time.
For example: a printer or a tape drive can’t be shared between two processes at
the same time.
So, it’s not possible to avoid mutual exclusion because these types of resources
are naturally non-shareable. Each process has to wait its turn to use them.

Eliminate Hold and Wait:


If we give a process all the resources it needs before
it starts, it avoids the hold and wait problem (where a process waits for
resources while holding others). But this can cause two problems:

• Wasted resources: For example, if a process gets a printer it doesn’t


need right away, the printer stays unused and blocked until needed.
• Starvation: After finishing and giving up its resources, the process
might need more later. If other processes keep taking those resources,
the first process could get stuck and never finish.
In simple terms, this avoids deadlock but can waste resources and delay some
processes forever.
.

Eliminate No Preemption :

Eliminating No Preemption means allowing resources to be taken away from a


process when a higher-priority process needs them.

In simple terms:

• Usually, when a process gets a resource (like memory or a printer), it


keeps it until it’s finished.
• But in this method, if a more important process needs that resource, the
system can take it away and give it to the higher-priority process

Eliminate Circular Wait :

To eliminate circular wait, the system assigns a numerical number to each


resource. When a process needs resources, it has to follow a specific order
based on those numbers. Here's how it works in simple terms:

1. Each resource gets a number (e.g., R1, R2, R3, etc.).


2. If a process (like P1) is using a resource (e.g., R2), it can only
request resources with a higher number next (e.g., R3, R4).
3. It cannot ask for resources with a lower number (e.g., R1).

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

Deadlock avoidance is a strategy used by


operating systems to ensure that resource allocation does not lead to a deadlock
situation. A deadlock occurs when two or more processes are unable to proceed
because each is waiting for the other to release resources.

Key Points:

• Declare Maximum Needs: Each process says how many resources it


might need at most.
• Request in Steps: Processes ask for resources one at a time, not all at
once.
• Safety Check: Before giving resources, the system checks if it’s safe or
if it could cause a deadlock later.
• Wait if Risky: If there’s any chance of a deadlock, the system delays
giving the resource until it’s safe.

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:

• The Banker's algorithm works only when the number of resources is


fixed.
• It is efficient for systems where resource requests are predictable and can
be handled in advance.

How it Works (Simple Steps):

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.

Deadlock prevention breaks one of the four deadlock conditions to stop


processes from getting stuck, but it can be complex and waste resources.
Deadlock avoidance, like the Banker's Algorithm, keeps the system safe by
carefully allocating resources, though it needs planning and can be slow.

The Banker's Algorithm is a smart way to avoid deadlocks by checking if


resource requests are safe, but it may underuse resources. Balancing efficiency,
simplicity, and safety ensures systems run smoothly without delays or
deadlocks.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy