TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Inter Process Communication (IPC) in Operating System

    Inter Process Communication (IPC) Kya Hai?

    Operating System me Inter Process Communication (IPC) ek aise mechanism ko refer karta hai jo alag-alag processes ko ek dusre se baat karne aur data share karne ka moka deta hai. Kyunki har process independent hoti hai aur apni alag memory space rakhti hai, IPC ek tarika hai jisse ye processes ek dusre se communicate kar sakein.

    Example Scenario:

    Maan lo tum Google Docs use kar rahe ho:

    • Ek process keyboard input handle kar rahi hai.

    • Dusri process real-time document saving ka kaam kar rahi hai.

    • Dono ko data exchange karna hoga taaki sab kuch smoothly chale.


    IPC Kyon Zaroori Hai?

    ✔ Process Synchronization: Ensure karta hai ki multiple processes coordinated tareeke se kaam karein.
    ✔ Data Sharing: Ek process doosri process ke saath data easily share kar sake.
    ✔ Resource Management: Agar ek se zyada processes ek hi resource use kar rahi hain to conflict avoid karne me madad karta hai.
    ✔ Modularity: Software ka design modular aur efficient banata hai.


    Types of IPC Mechanisms

    IPC message-based ya shared memory-based ho sakta hai.

    1. Message Passing

    • Processes OS kernel ke through ek dusre ko messages bhejti hain.

    • Thoda slow hota hai, par safe hota hai.

    • Distributed systems me zyada use hota hai.

    • Example: Chat applications jisme alag devices ek dusre ko messages bhejti hain.

    2. Shared Memory

    • Multiple processes ek common memory segment share karti hain.

    • Faster hota hai but synchronization chahiye taaki koi conflict na ho.

    • Example: Google Chrome ke multiple tabs shared memory ka use karte hain.


    IPC Methods in Detail

    1. Pipes

    • Unidirectional communication ka use hota hai (data ek hi direction me flow karta hai).

    • Mostly parent-child processes ke beech use hota hai.

    • Example: Linux shell command ls | grep "txt" pipes ka use karti hai taaki ls ka output grep ko mile.

    Diagram:

    Process A (Writes) ──> Pipe ───> Process B (Reads)


    2. Named Pipes (FIFO)

    • Normal pipes ki tarah hi hota hai, but iska ek naam hota hai.

    • Unrelated processes bhi communicate kar sakti hain.

    Example:

    Linux me named pipe (FIFO file) ka use karke:

    mkfifo mypipe
    Process1 > echo "Hello" > mypipe
    Process2 > cat < mypipe
     

    3. Message Queues

    • Ek queue-like structure hota hai jisme OS temporarily messages store karta hai.

    • Asynchronous communication ke liye use hota hai.

    Diagram:

    Process A ───> Message Queue ───> Process B

    Example:

    Ek ATM System me alag-alag processes:

    • Cash withdrawal request handle karti hai.

    • Balance update karti hai.

    • Transaction logging karti hai.

    Ye sab processes message queues ka use karke communicate karti hain.


    4. Shared Memory

    • Processes ek common memory segment share karti hain taaki fast communication ho sake.

    • Synchronization techniques (like semaphores) ki zaroorat hoti hai taaki data corrupt na ho.

    • Fastest IPC method hai.

    Diagram:

    Process A ───> [ Shared Memory Segment ] <─── Process B

    Example:

    Ek video streaming application me:

    • Ek process network se frames fetch karti hai.

    • Dusri process frames decode aur display karti hai.

    • Dono shared memory ka use karke fast data exchange karti hain.


    5. Sockets

    • Network ke upar processes ko communicate karne ke liye use hota hai.

    • Local (same system) aur remote (different systems) dono ke liye kaam karta hai.

    • Client-server applications me zyada use hota hai.

    Diagram:

    Client Process ───> [ Network Socket ] ───> Server Process

    Example:

    • Web Browsers aur Web Servers internet ke upar communicate karne ke liye sockets ka use karte hain.


    Comparison of IPC Methods

    IPC MethodSpeedComplexityBest Use Case
    PipesMediumSimpleParent-child process communication
    Named PipesMediumMediumUnrelated process communication
    Message QueuesSlowMediumAsynchronous communication
    Shared MemoryFastComplexHigh-speed data exchange
    SocketsSlowComplexNetwork-based communication

    Synchronization in IPC

    Agar multiple processes ek saath shared resources use kar rahi hain, to synchronization zaroori hoti hai taaki conflicts na ho.

    Synchronization Techniques:

    1. -> Semaphores – Ek tarika hai jisse processes ek dusre ko wait karwa sakti hain.

    2. -> Mutex (Mutual Exclusion Object) – Ensure karta hai ki ek samay me sirf ek process shared data ko access kare.

    3. -> Monitors – High-level synchronization method hai jo multiple threads ke access ko control karta hai.


    Conclusion

    ✔ IPC processes ke beech communication ke liye bahut zaroori hota hai.
    ✔ Alag-alag IPC mechanisms use hote hain based on requirement.
    ✔ Synchronization zaroori hai jab processes shared memory ka use karti hain.

    Scroll to Top