BCA / B.Tech 13 min read

Monitor in Hindi

RK

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

प्रकाशित:

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

  • • विषय फोकस: Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Monitor in Hindi - General Topics
  • • अवलोकन: Quick Answer: Operating System mein Monitor ek high-level synchronization construct (प्रोग्रामिंग संरचना) hai jiska use concurrent processes ke beech Mu...
  • • मुख्य अवधारणाएं: Monitor, Condition variables wait signal Hindi, Dining philosophers monitor,Monitor, Condition variables wait signal, Dining philosophers monitor
Quick Answer: Operating System mein Monitor ek high-level synchronization construct (प्रोग्रामिंग संरचना) hai jiska use concurrent processes ke beech Mutual Exclusion aur coordination ensure karne ke liye hota hai. Monitor shared data variables, entry procedures aur Condition Variables (wait() aur signal()) ko ek single module mein encapsulate karta hai. Semaphore ke mukable monitor ka sabse bada benefit yah hai ki isme mutual exclusion compiler dwara automatically enforce hota hai, jisse programmer ki manual locking mistakes aur race conditions khatam ho jaati hain.

Operating System mein Monitor kya hai aur iski Zaroorat kyon padi?

Multi-programming operating system mein jab multiple processes ek hi shared memory ya resource (jaise shared buffer, counter, printer) ko simultaneously access karti hain, toh data inconsistency aur Race Condition paida ho sakti hai. Ise rokne ke liye critical section coordination ki zaroorat padti hai. Is concept ko samajhne ke liye aap hamare Critical Region in OS aur Inter-Process Communication in OS notes padh sakte hain.

Pehle synchronization ke liye low-level primitives jaise Semaphores (P aur V operations) use kiye jaate the. Lekin semaphores programmer-dependent hote hain. Agar programmer galti se signal() call karna bhool jaaye ya wait() aur signal() ka sequence ulta-pulta likh de, toh system mein Deadlock ho jaata hai.

Is programming complexity ko solve karne ke liye 1970s mein C.A.R. Hoare aur Per Brinch Hansen ne Monitors ka concept propose kiya. Monitor ek high-level abstract data type (ADT) ya class ki tarah hota hai jiske andar shared variables aur unhe access karne wale functions ek sath bandhe rehte hain.

Advertisement

Monitor ki Internal Structure aur Components

Monitor ki structure mukhya roop se teen core parts se milkar banti hai:

1. Shared Private Variables

Yah wah data hota hai jise multiple processes share karna chahti hain (jaise buffer array, item counter). Monitor ke private variables ko bahar se direct koi bhi process access ya modify nahi kar sakti; sirf monitor ke entry procedures ke through hi in tak pahuncha ja sakta hai.

2. Entry Procedures (Public Methods)

Monitor ke andar define kiye gaye public functions (jaise produce() aur consume()) jinhe outside processes call karti hain. Golden Rule of Monitor: Ek samay par sirf ek hi process kisi monitor procedure ke andar actively execute kar sakti hai. Doosri sabhi calling processes monitor ke bahar entry queue mein automatically wait karti hain.

3. Condition Variables (कंडीशन वेरिएबल्स)

Monitor ke andar complex synchronization ko manage karne ke liye condition data type use hota hai (jaise condition full, empty;). Condition variable par sirf do operations allowed hote hain:

Semaphore ko detail mein samajhne ke liye padhein: Semaphore in OS in Hindi.

  • x.wait(): Jo process ise call karti hai, wah turant suspend ho jaati hai aur monitor ka lock release kar deti hai taaki doosri process monitor mein enter kar sake. Suspended process condition x ki waiting queue mein lag jaati hai.
  • x.signal(): Yah operation condition x par wait kar rahi kisi ek suspended process ko resume (wake up) karta hai. Agar koi process wait nahi kar rahi hai, toh signal() ka koi effect nahi hota.

Monitor Syntax ka Blueprint (Pseudo-code)

Standard monitor structure ka high-level syntax neeche diya gaya hai:

monitor MonitorName {
    // 1. Shared private data variables
    private int buffer[100];
    private int count;
    condition not_full, not_empty;

    // 2. Entry Procedure 1
    public entry void insertItem(int item) {
        if (count == 100) {
            not_full.wait(); // Buffer full hai, wait karein
        }
        buffer[count] = item;
        count++;
        not_empty.signal(); // Consumer ko signal bhejein
    }

    // 3. Entry Procedure 2
    public entry int removeItem() {
        if (count == 0) {
            not_empty.wait(); // Buffer khali hai, wait karein
        }
        count--;
        int item = buffer[count];
        not_full.signal(); // Producer ko signal bhejein
        return item;
    }

    // 4. Initialization code
    init {
        count = 0;
    }
}

Condition Signaling Semantics: Hoare vs Mesa Style

Jab Process P monitor ke andar x.signal() call karti hai aur Process Q condition x par wait kar rahi hoti hai, toh immediate control kiske paas jaayega? Is par do pramukh approaches hain:

  1. Signal-and-Wait (Hoare Style): Signaler process P turant suspend ho jaati hai aur monitor ka lock chhod deti hai, jabki waiting process Q turant monitor mein execution resume karti hai. Yah theoretically pure hai par implementation mein context switch badhata hai.
  2. Signal-and-Continue (Mesa Style / Java Style): Signaler process P monitor ke andar apna execution continue karti hai. Resumed process Q ready queue mein chali jaati hai aur monitor lock free hone par turn leti hai. Is style mein wake-up ke baad condition dobara check karne ke liye while (!condition) wait(); loop use hota hai.

Monitor Components Reference Table

Neeche diye gaye table mein monitor ke sabhi elements aur unka functional purpose summarize kiya gaya hai:

Component Name Access Level Primary Responsibility
Shared Variables Private (Internal) Shared state data store karta hai; external access completely blocked hota hai.
Entry Procedures Public (External) Processes ke liye gate ka kaam karta hai; automatic mutual exclusion enforce karta hai.
Condition Variable (wait) Internal Operation Calling process ko suspend karke monitor lock turant release karta hai.
Condition Variable (signal) Internal Operation Condition queue mein block kisi ek process ko unblock/wake-up karta hai.
Entry Queue System Managed Un processes ko queue karta hai jo busy monitor mein enter hone ke liye wait kar rahi hain.
Advertisement

Comparison: Semaphores vs Monitors

Operating System ke do sabse mahatvapurna synchronization constructs ka comparison neeche table mein dekhein:

Comparison Parameter Semaphore Monitor
Construct Level Low-level integer variable construct. High-level programming language construct (ADT / Class).
Mutual Exclusion Programmer ko manual roop se wait() aur signal() code likhkar manage karna padta hai. Compiler dwara automatic roop se enforce hota hai; ek samay par ek hi process andar allowed hai.
Error Prone High risk; agar ek bhi wait()/signal() galat ho jaaye toh deadlock ho sakta hai. Much safer; programming bugs aur race condition ke chances bahut kam hote hain.
Data Encapsulation Shared data aur semaphore alag-alag scattered rehte hain. Shared data aur access methods ek hi container block ke andar encapsulated hote hain.
Implementation Example POSIX Semaphores (sem_wait, sem_post in C/C++). Java synchronized keyword, wait() aur notify() methods.

Real-World Example: Java mein Object Monitor

Modern programming languages mein monitor ka sabse famous implementation Java mein milta hai. Java mein har object ke sath internally ek monitor lock associated hota hai. Jab hum kisi method ko synchronized declare karte hain, toh wah method monitor entry procedure ban jaati hai:

public class SharedBuffer {
    private int data;
    private boolean hasData = false;

    // Monitor Entry Procedure 1
    public synchronized void produce(int value) throws InterruptedException {
        while (hasData) {
            wait(); // Condition wait: buffer already full
        }
        data = value;
        hasData = true;
        System.out.println("Produced: " + value);
        notify(); // Condition signal: wake up consumer
    }

    // Monitor Entry Procedure 2
    public synchronized int consume() throws InterruptedException {
        while (!hasData) {
            wait(); // Condition wait: buffer empty
        }
        hasData = false;
        System.out.println("Consumed: " + data);
        notify(); // Condition signal: wake up producer
        return data;
    }
}

Common Mistakes to Avoid

  • Semaphore ke signal() aur Monitor ke condition.signal() mein farq na samajhna: Semaphore ka signal integer value ko increment karta hai chahe koi wait kar raha ho ya na ho; jabki Monitor ka condition signal sirf tab asar karta hai jab koi process already waiting queue mein ho, warna signal discard ho jaata hai (no memory).
  • Condition check ke liye if statement use karna; Mesa-style monitors mein hamesha while (!condition) wait(); loop use karein taaki spurious wake-up ke baad bhi condition re-verify ho sake.
  • Monitor ko hardware device samajhna; computer screen wale monitor se confuse na hon, OS mein yah software synchronization construct hota hai.

Exam के लिए Important Questions

Short Questions (2-3 marks)

  1. Operating System mein Monitor kya hota hai aur iska primary goal kya hai?
  2. Condition variable ke wait() aur signal() operations kaise kaam karte hain?
  3. Monitor Semaphore se zyada secure aur reliable kyon maana jaata hai?
  4. Hoare style aur Mesa style condition signaling mein kya antar hai?

Long Questions (5-10 marks)

  1. Operating System mein Monitor ki internal structure aur working mechanism par vistaar se charcha kijiye. Shared data, entry procedures aur condition variables ko diagram sahit explain kijiye.
  2. Semaphores aur Monitors ke beech tulnatmak antar (comparison) table banakar spasht kijiye. Monitors ne race condition problem ko kaise aasan banaya?
  3. Bounded Buffer Producer-Consumer problem ko Monitor ka use karke solve kijiye aur uska pseudo-code / Java implementation likhiye.

Frequently Asked Questions (FAQs)

Kya ek monitor ke andar do processes ek sath run ho sakti hain?

Nahi, monitor ka basic rule yahi hai ki kisi bhi instant par sirf ek hi process monitor ke active code ko execute kar sakti hai. Doosri processes entry queue ya condition queues mein wait karti hain.

Java mein 'synchronized' keyword aur monitor ka kya sambandh hai?

Java mein synchronized keyword monitor entry lock acquire karta hai. Jab tak thread synchronized block ke andar hai, koi doosra thread us object ke kisi anya synchronized method mein enter nahi ho sakta.

Condition variables mein 'broadcast' ya 'signalAll' kya hota hai?

Simple signal() sirf ek waiting process ko jagata hai, jabki signalAll() ya Java ka notifyAll() us condition par wait kar rahi sabhi suspended processes ko ek sath unblock kar deta hai.

Deadlock se bachne ke liye monitor mein kya care leni chahiye?

Nested monitor calls (jab ek monitor procedure ke andar se doosre monitor ka procedure call kiya jaaye) se bachna chahiye, kyunki isse circular wait ban kar deadlock ho sakta hai.

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

Quick Answer: Operating System mein Monitor ek high-level synchronization construct (प्रोग्रामिंग संरचना) hai jiska use concurrent processes ke beech Mutual Exclusion aur coordination ensure karne ke liye hota hai.
Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स के पाठ्यक्रम में Monitor in Hindi एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको Monitor in Hindi के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement

In this Chapter

Monitor 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
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
Deadlock & Characterization 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