Deadlock Avoidance

Introduction

Deadlock Prevention में हमने देखा कि system को इतना restrict कर दिया जाता है कि deadlock हो ही नहीं सकता।

लेकिन इससे problem यह होती है कि:

  • Resource utilization कम हो जाता है
  • System flexible नहीं रहता

इसलिए एक smarter approach use की जाती है: Deadlock Avoidance

Deadlock Avoidance क्या होता है

Deadlock Avoidance वह technique है जिसमें system पहले से check करता है कि resource allocate करने से system safe रहेगा या नहीं।

अगर unsafe state बनेगी, तो resource allocate नहीं किया जाता।

Simple Definition

Deadlock Avoidance = unsafe state को avoid करना

Basic Idea (सबसे important)

हर resource request के समय system check करता है:

  • अगर resource देने से system safe रहेगा → allow
  • अगर unsafe होगा → deny

Safe State क्या होता है

Safe State वह स्थिति है जिसमें system सभी processes को बिना deadlock के complete कर सकता है।

Unsafe State क्या होता है

Unsafe State वह स्थिति है जहाँ future में deadlock होने की संभावना होती है।

ध्यान रहे:
Unsafe state = deadlock नहीं है
लेकिन deadlock की संभावना है

Safe Sequence

Safe Sequence वह order होता है जिसमें सभी processes safely execute हो सकते हैं।

Example:

P1 → P2 → P3

अगर इस order में सभी processes complete हो जाएँ → system safe है

Working (Step-by-Step समझो)

  1. Process resource request करता है
  2. System temporarily resource allocate करके check करता है
  3. Safe sequence possible है या नहीं
  4. अगर safe है → allocation confirm
  5. नहीं है → request deny

Example

मान लो:

  • Total resources = 10
  • Processes को कुछ resources चाहिए

अगर system यह check करता है कि सभी processes को eventually resources मिल सकते हैं, तो allocation safe है

अगर नहीं → request reject

Main Algorithm

Deadlock Avoidance के लिए सबसे famous algorithm है:

Banker’s Algorithm

Banker’s Algorithm

यह algorithm bank के जैसे काम करता है:

  • Bank तभी loan देता है जब उसे विश्वास हो कि पैसा वापस आएगा
  • वैसे ही OS resource तभी देता है जब safe state maintain हो

Banker’s Algorithm में use होने वाले terms

  • Available → available resources
  • Max → process की maximum demand
  • Allocation → already allocated resources
  • Need → और कितने resources चाहिए

Advantages

  • Deadlock avoid करता है
  • System flexible रहता है
  • Resource utilization better होता है

Disadvantages

  • System को advance information चाहिए
  • Complex calculation होता है
  • हर request पर checking करनी पड़ती है

Prevention vs Avoidance (Important Difference)

PreventionAvoidance
Conditions break करता हैSafe state check करता है
Strict approachSmart approach
Resource utilization कमBetter utilization

Exam Focus Points

  • Safe state, Unsafe state
  • Safe sequence
  • Banker’s Algorithm
  • Prevention vs Avoidance

Conclusion

Deadlock Avoidance एक intelligent technique है जो system को unsafe state में जाने से रोकती है और resource allocation को efficiently manage करती है।

यह prevention से बेहतर है क्योंकि यह flexibility और performance दोनों को maintain करता है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top