BCA / B.Tech 12 min read

Deadlock & Characterization in Hindi

RK

लेखक Ratan Kumawat · संस्थापक, NotesMedia

प्रकाशित:

त्वरित सारांश और मुख्य बिंदु

  • • विषय फोकस: Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Deadlock & Characterization in Hindi - General Topics
  • • अवलोकन: Quick Answer: Operating system में Deadlock एक ऐसी स्थिति है जहाँ दो या दो से ज़्यादा processes एक-दूसरे के resources (जैसे printer, memory, files) hol...
  • • मुख्य अवधारणाएं: Deadlock characterization, Mutual exclusion hold wait Hindi, No preemption circular,
Quick Answer: Operating system में Deadlock एक ऐसी स्थिति है जहाँ दो या दो से ज़्यादा processes एक-दूसरे के resources (जैसे printer, memory, files) hold करके बैठ जाते हैं और एक-दूसरे के resources release होने का wait करते रहते हैं। इस वजह से कोई भी process execute नहीं हो पाता और पूरा system हमेशा के लिए अटक जाता है। Deadlock बनने के लिए 4 Coffman conditions का एक साथ होना ज़रूरी है: Mutual Exclusion, Hold and Wait, No Preemption, और Circular Wait।

Deadlock in OS in Hindi क्या है? (Deadlock Meaning)

"Deadlock" शब्द का सीधा मतलब है पूरी तरह अटक जाना, जहाँ आगे बढ़ने का कोई रास्ता न बचे। OS में जब कई processes एक साथ run होते हैं और shared resources के लिए compete करते हैं, तब deadlock की स्थिति बन सकती है।

मान लीजिए दो processes हैं: P1 और P2, और दो non-shareable resources हैं: R1 (Printer) और R2 (Scanner):

  • Process P1 ने Printer (R1) allocate करा रखा है और वह Scanner (R2) की request भेजकर wait कर रहा है।
  • Process P2 ने Scanner (R2) allocate करा रखा है और वह Printer (R1) की request भेजकर wait कर रहा है।
  • P1 तब तक Printer नहीं छोड़ेगा जब तक उसे Scanner न मिले, और P2 तब तक Scanner नहीं छोड़ेगा जब तक उसे Printer न मिले।

दोनों processes हमेशा के लिए blocked रह जाते हैं। इसी स्थिति को Deadlock in Operating System कहते हैं। Processes के आपसी तालमेल को समझने के लिए interacting processes in OS और Inter Process Communication in Hindi का concept काम आता है।

Advertisement

Real-life Traffic Bridge Example

एक संकरा single-lane bridge है जिस पर एक समय में सिर्फ एक गाड़ी निकल सकती है। अगर दोनों तरफ से दो गाड़ियाँ bridge के बीच में आमने-सामने आ जाएँ, तो न पहली गाड़ी आगे बढ़ सकती है और न दूसरी। जब तक कोई एक गाड़ी पीछे न हटे, रास्ता खाली नहीं होगा। OS में जब resources shareable नहीं होते और कोई process अपना resource छोड़ने को तैयार नहीं होता, तो ठीक यही deadlock बनता है।

Deadlock Characterization: 4 Coffman Conditions

1971 में Edward G. Coffman Jr. ने बताया कि deadlock तभी बनता है जब ये 4 conditions एक ही समय पर मौजूद हों। इन्हें Coffman conditions कहते हैं। इनमें से एक भी condition तोड़ दी जाए तो system में deadlock नहीं आ सकता:

1. Mutual Exclusion

कम से कम एक resource non-shareable होना चाहिए, जिसे एक समय में सिर्फ एक ही process use कर सके (जैसे Printer या Tape Drive)। अगर कोई दूसरा process उसकी request करता है, तो उसे wait करना होगा। Read-only files shareable होती हैं, इसलिए उनसे deadlock नहीं बनता। Shared resources के critical section को safe रखने के लिए critical region in OS का नियम लागू होता है।

2. Hold and Wait

एक process ने कम से कम एक resource hold कर रखा है और साथ ही वह दूसरे processes के पास locked resources के लिए wait कर रहा है।

3. No Preemption

Resource को किसी process से जबरन नहीं छीना जा सकता। Resource सिर्फ तभी free होगा जब उसे hold करने वाला process अपना execution पूरा करके खुद अपनी मर्जी से release करे।

4. Circular Wait

Waiting processes की एक ऐसी बंद chain बन जाती है जहाँ हर process अगले process के resource का इंतज़ार कर रहा होता है: P0 wait कर रहा है P1 के resource का, P1 wait कर रहा है P2 के resource का, और Pn wait कर रहा है P0 के resource का।

Coffman Condition मतलब OS पर असर रोकने का उपाय
Mutual Exclusion एक समय में सिर्फ 1 process Resource share नहीं हो सकता Spooling use करें या resource shareable बनाएँ
Hold and Wait एक resource पकड़ो, दूसरे का wait करो Process resources दबाकर नए माँगता है शुरुआत में ही सारे resources लें या hold न करें
No Preemption Resource छीना नहीं जा सकता Process की मर्जी के बिना resource free नहीं होता Request पूरी न होने पर पुराने resources preempt करें
Circular Wait Processes का बंद loop (cycle) P0 → P1 → P2 → P0 का loop बन जाता है Resources को numbering दें और strictly increasing order में allocate करें

Resource Allocation Graph (RAG) और Deadlock

Deadlock को graph के रूप में दिखाने के लिए Resource Allocation Graph (RAG) का इस्तेमाल किया जाता है। यह एक directed graph G = (V, E) होता है:

  • Vertices (V): दो तरह के nodes होते हैं:
    • Processes (P): Circle से दिखाते हैं (P1, P2...)।
    • Resources (R): Box से दिखाते हैं (R1, R2...), और अंदर के dots instances की संख्या बताते हैं।
  • Edges (E): दो तरह के directed edges होते हैं:
    • Request Edge (Pi → Rj): Process Pi ने Resource Rj की request की है और wait कर रहा है।
    • Assignment Edge (Rj → Pi): Resource Rj Process Pi को allocate हो चुका है।

RAG Deadlock Rules

  1. Graph में Cycle नहीं है: System में 100% deadlock नहीं है।
  2. Graph में Cycle मौजूद है:
    • Single Instance per Resource: अगर हर resource का सिर्फ 1 instance है, तो Cycle का मतलब निश्चित रूप से Deadlock है।
    • Multiple Instances per Resource: अगर resources के एक से ज़्यादा instances हैं, तो Cycle होने पर deadlock हो भी सकता है और नहीं भी।
Single Instance RAG Deadlock Cycle:

       +---------+
       |   R1    | <----------+
       +----+----+            |
            |                 |
       Assignment          Request
            |                 |
            v                 |
       (   P1   )             |
            |                 |
         Request              |
            |                 |
            v                 |
       +----+----+            |
       |   R2    |            |
       +----+----+            |
            |                 |
       Assignment             |
            |                 |
            v                 |
       (   P2   ) ------------+

Worked Example: Deadlock Detection Trace

Exam में trace tables पूछे जाते हैं। आइए single और multiple instances के दोनों cases को step-by-step समझें।

Scenario 1: Single Instance Deadlock Trace

दो processes (P1, P2) और दो resources (R1, R2) हैं। दोनों resources का सिर्फ 1-1 instance उपलब्ध है।

Process Allocated Resource (Hold) Requested Resource (Wait) Status
P1 R1 R2 Blocked (R2 का wait)
P2 R2 R1 Blocked (R1 का wait)

Trace Steps:

  1. P1 को R2 चाहिए, लेकिन R2 Process P2 के पास है।
  2. P2 को R1 चाहिए, लेकिन R1 Process P1 के पास है।
  3. Cycle path बनता है: P1 → R2 → P2 → R1 → P1।
  4. हर resource का 1 instance है और cycle मौजूद है, इसलिए यह Confirmed Deadlock है।

Scenario 2: Multiple Instances With Cycle (No Deadlock)

अब एक ऐसा case देखते हैं जहाँ cycle होने के बाद भी deadlock नहीं बनता:

  • Resources: R1 (2 instances), R2 (2 instances)
  • Processes: P1, P2, P3, P4
Process Allocated Resources Requesting Resources Result
P1 R1 (1 instance) R2 (1 instance) Wait कर रहा है
P2 R2 (1 instance) R1 (1 instance) Wait कर रहा है
P3 R1 (1 instance) कोई request नहीं Free run कर रहा है
P4 R2 (1 instance) कोई request नहीं Free run कर रहा है

Trace Analysis: P1 और P2 के बीच cycle दिखती है। लेकिन R1 का दूसरा instance P3 के पास है और R2 का दूसरा instance P4 के पास है। जैसे ही P3 काम पूरा करके R1 release करेगा, वह P2 को मिल जाएगा। P2 का execution खत्म होते ही R2 free होकर P1 को मिल जाएगा। इसलिए cycle होने पर भी Deadlock नहीं हुआ।

Deadlock Handling Strategies in Operating System

OS में deadlock संभालने के 4 मुख्य तरीके होते हैं:

1. Deadlock Prevention

System को ऐसे design करना कि 4 Coffman conditions में से कम से कम 1 condition कभी पूरी न हो सके।

  • Mutual Exclusion हटाना: Spooling तकनीक से resources को shareable बनाना।
  • Hold and Wait हटाना: Process को execution शुरू होने से पहले ही सारे resources एक साथ allocate करना।
  • No Preemption हटाना: अगर नया resource न मिले, तो process के पुराने resources preempt (छीन) लेना।
  • Circular Wait हटाना: सभी resources को integer numbers देना और rule बनाना कि process सिर्फ increasing order of numbers में ही request कर सके। यह सबसे practical तरीका है।

2. Deadlock Avoidance

OS हर request पर dynamically check करता है कि resource देने के बाद system Safe State में रहेगा या Unsafe State में जाएगा। Unsafe state का खतरा होने पर request रोक दी जाती है। इसका सबसे प्रसिद्ध उदाहरण Banker's Algorithm है, जिसे Edsger Dijkstra ने बनाया था।

Advertisement

3. Deadlock Detection and Recovery

System में deadlock होने दिया जाता है। समय-समय पर detection algorithm चलाकर deadlock ढूँढा जाता है, और फिर recovery की जाती है:

  • Process Termination: Deadlock में फँसे processes को kill कर देना।
  • Resource Preemption: किसी process से resource छीनकर दूसरे को देना और पहले process को rollback करना।

4. Deadlock Ignorance (Ostrich Algorithm)

Deadlock की समस्या को पूरी तरह नजरअंदाज कर देना। Windows और Linux जैसे modern OS यही approach अपनाते हैं, क्योंकि deadlock बहुत कम होता है और हर समय prevention algorithms चलाने से CPU performance slow हो जाती है। अगर deadlock हो, तो user खुद process kill या system reboot कर देता है।

Handling Method काम करने का तरीका Resource Utilization OS Overhead
Deadlock Prevention 4 conditions में से 1 को रोकना कम (Low) कम
Deadlock Avoidance Banker's Algorithm से safe state जाँचना मध्यम (Medium) ज्यादा (हर request पर calculation)
Detection & Recovery Deadlock ढूँढकर processes kill करना अच्छा (Good) मध्यम
Deadlock Ignorance कुछ मत करो, user reboot करेगा सबसे ज्यादा (Best) शून्य (Zero overhead)

Difference Between Deadlock and Starvation

तुलना का आधार Deadlock Starvation
Definition Processes एक-दूसरे के resources के इंतज़ार में हमेशा के लिए रुक जाते हैं। High priority processes के आने से low priority process को resource नहीं मिलता।
Condition चारों Coffman conditions एक साथ लागू होती हैं। Unfair scheduling policy के कारण होता है।
Processes कम से कम दो या उससे ज़्यादा processes फँसते हैं। एक अकेला single process भी starve हो सकता है।
Resource State Resources blocked processes ने hold कर रखे होते हैं। Resources लगातार use हो रहे हैं, पर दूसरे processes को मिल रहे हैं।
समाधान Process kill करना या rollback करना। Aging technique (wait time बढ़ने पर priority बढ़ाना)।

Exam में कैसे लिखें (5 Marks Ready Answer)

University exam (MDSU / RTU BCA/MCA) में 5 marks के सवाल के लिए उत्तर इस तरह point-wise लिखें:

  1. Definition: Deadlock OS की वह blocked state है जहाँ दो या अधिक processes एक-दूसरे के resources release होने के इंतज़ार में हमेशा के लिए रुक जाते हैं।
  2. Example: Process P1 hold करता है R1 और request करता है R2। Process P2 hold करता है R2 और request करता है R1। दोनों circular wait में अटक जाते हैं।
  3. 4 Coffman Conditions:
    • Mutual Exclusion: Resource non-shareable हो।
    • Hold and Wait: Resource पकड़कर नए resource का wait करना।
    • No Preemption: Resource जबरन नहीं छीना जा सकता।
    • Circular Wait: Processes का closed cycle (P0 → P1 → ... → P0)।
  4. RAG Diagram: Answer sheet में P1, P2 और R1, R2 का cycle diagram पेंसिल से बनाएँ।
  5. Handling Methods: Prevention, Avoidance (Banker's Algorithm), Detection & Recovery, और Ignorance (Ostrich Algorithm)।

Common Mistakes Students Make on This Topic

  • गलती 1: हर Cycle को Deadlock मान लेना। अगर resource के multiple instances हैं, तो graph में cycle होने पर भी deadlock होना ज़रूरी नहीं है (जैसा ऊपर Scenario 2 में दिखाया गया है)। Cycle सिर्फ single-instance case में ही 100% deadlock बनाती है।
  • गलती 2: Starvation और Deadlock को एक समझना। Deadlock में पूरा system रुक जाता है। Starvation में system चल रहा होता है, सिर्फ एक low priority process को मौका नहीं मिलता।
  • गलती 3: Prevention और Avoidance में confusion। Prevention का मतलब नियमों से conditions को पहले ही खत्म करना है। Avoidance का मतलब dynamic calculation से safe state बनाए रखना है।
  • गलती 4: Windows और Linux को Deadlock-free समझना। Windows और Linux deadlock prevention run नहीं करते; वे Ostrich algorithm use करते हैं ताकि CPU fast चले।

Exam के लिए Important Questions

Short Questions (2–3 marks)

  1. Deadlock क्या है? (Processes का एक-दूसरे के resources के इंतज़ार में permanently रुक जाना)
  2. Deadlock Characterization की 4 necessary conditions के नाम लिखिए। (Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait)
  3. Resource Allocation Graph (RAG) में Request Edge और Assignment Edge में क्या फ़र्क है? (Request edge: Process → Resource; Assignment edge: Resource → Process)
  4. Ostrich Algorithm क्या है? (Deadlock को अनदेखा करने का तरीका जो commercial OS अपनाते हैं)
  5. Aging technique से कौन सी समस्या हल होती है? (Starvation)

Long Questions (5–10 marks)

  1. Deadlock in OS क्या है? Deadlock Characterization की चारों Coffman conditions को example के साथ detail में समझाइए।
  2. Resource Allocation Graph (RAG) क्या है? Single instance और Multiple instances resources में deadlock detection के नियमों को diagram के साथ समझाइए।
  3. Deadlock Prevention और Deadlock Avoidance में अंतर बताइए। Circular wait condition को कैसे रोका जा सकता है?
  4. Deadlock और Starvation में अंतर बताइए और deadlock से recovery के उपाय लिखिए।

FAQs

What is deadlock in OS in simple words?

सरल शब्दों में, Deadlock कंप्यूटर में processes का ऐसा जाम है जहाँ दो या अधिक processes एक-दूसरे के resources छोड़ने का इंतज़ार करते रहते हैं और कोई भी आगे नहीं बढ़ पाता, जिससे system रुक जाता है।

Deadlock characterization की चारों conditions एक साथ होना क्यों जरूरी है?

क्योंकि अगर इनमें से एक भी condition मौजूद न हो, तो deadlock टूट जाता है। जैसे अगर Circular Wait न हो, तो chain का आखिरी process काम पूरा करके resource release कर देगा और बाकी processes भी चल पड़ेंगे।

क्या modern operating systems खुद deadlock ठीक कर लेते हैं?

नहीं, सामान्य Desktop और Server OS (जैसे Windows, Linux) Deadlock Ignorance (Ostrich Algorithm) अपनाते हैं। वे background में deadlock check नहीं करते ताकि speed कम न हो। Deadlock होने पर process को manually kill करना पड़ता है।

Banker's Algorithm deadlock prevention है या avoidance?

Banker's Algorithm Deadlock Avoidance तकनीक है। यह resource allocate करने से पहले check करता है कि allocation के बाद system Safe State में रहेगा या नहीं।

अक्सर पूछे जाने वाले प्रश्न (FAQs)

Quick Answer: Operating system में Deadlock एक ऐसी स्थिति है जहाँ दो या दो से ज़्यादा processes एक-दूसरे के resources (जैसे printer, memory, files) hold करके बैठ जाते हैं और एक-दूसरे के resources release होने का wait करते रहते हैं।
Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स के पाठ्यक्रम में Deadlock & Characterization in Hindi एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको Deadlock & Characterization in Hindi के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement

In this Chapter

Deadlock & Characterization in Hindi
Distributed System in Hindi
Real Time System in Hindi
System Calls in Hindi
System Program in Hindi
Structure of Operating System in Hindi
Layers Design of Structure in Hindi
Unix in Hindi
Virtual Machine in Hindi
Kernel-Based Operating System in Hindi
Process in Hindi – OS में Process क्या है
Interacting Processes in Hindi
Threads in Hindi
Fundamental of Schedulling in Hindi
Scheduling Criteria in Hindi
Long Medium Short Term Scheduling in Hindi
Scheduling Algorithms in Hindi
Structure of Concurrent System in Hindi
Critical Region in Hindi
Critical Section in Hindi
Inter process Communication in Hindi
Monitor in Hindi
Semaphore in OS in Hindi – Counting और Binary Semaphore
Semaphores Implementation & Uses in Hindi
Logical and Physical Address in Hindi
Swapping in Hindi
Contiguous Allocation in Hindi
Segmentation in Hindi
Paging in OS in Hindi – Paging और Segmentation
Paging with Segmentation in Hindi
kernel Memory Allocation in Hindi
Page Replacement Algorithms in Hindi
Virtual Memory in Hindi
Virtual Memory with demand Paging in Hindi
Methods for Handling Deadlocks in Hindi
Deadlock Thrashing in Hindi
Allocation of Frames in Hindi
Virtual Memory using Segmentation in Hindi
Interprocess Communication protocol in Hindi
Network Operating System in Hindi
Design Issues in Distributed File System in Hindi
Network Structure in Hindi
Structure Distributed System in Hindi
File System and Coordination in Hindi
Linux in Hindi
Commands of Linux in Hindi | लिनक्स के कमांड्स हिंदी में
Programmer Interface & File manipulation in Hindi
Process control in Linux in Hindi
Linux Kernel & Signals in Hindi
File System in Linux in Hindi
block & inodes in Hindi
System Editor in Hindi
Character Transliteration in Hindi
ED in Hindi
Vi Editor & There Commands in Hindi
Shell Script in Hindi
Looping & Decision Making in Hindi
Variables & File name Expansion in Hindi
Array in Hindi OS
Sub Program in Hindi
C interface with Linux in Hindi
Simpel Shell Programs in Hindi
BCA Part-1 | Operating Systems | Semester-I | MDSU Exam Paper 2023 (Held in 2024)
What is Operating System (OS) in Hindi
Operating System (OS) All Important Questions and Answers in Hindi (MDSU)
BCA || Operating System 2025 Paper || MDSU Exam Paper
BCA | OS(Operating System) 2023 Paper | MDSU Exam Paper
Type of Operating System in Hindi
Goals of Operating System in Hindi
Operation of Operating system in Hindi
Resource Allocation & Functions in Hindi
class of Operating system in Hindi
Batch Processing in Hindi
Multi Processing in Hindi
Time Sharing in Hindi