What is IPC (Inter-Process Communication)?

Modern operating systems run many processes at the same time.
But often, these processes need to talk to each other — share data, send signals, or synchronize actions.

This is where IPC — Inter-Process Communication comes in.
It’s the set of mechanisms that allows processes to exchange information safely.


Why do we need IPC?

  • To share data (e.g., a browser rendering process sends results to the UI process).
  • To coordinate actions (e.g., a parent process waits for a child process to finish).
  • To send signals/events (e.g., one service notifies another about new data).

Without IPC, each process would live in its own isolated world.


Common IPC Methods

  1. Pipes

    • Unidirectional channel between processes.
    • Example: ls | grep "txt" — shell connects two processes via a pipe.
  2. Message Queues

    • Processes put messages in a queue; others read them.
    • Good for async communication.
  3. Shared Memory

    • Fastest way — multiple processes access the same memory segment.
    • Needs synchronization (mutex, semaphore).
  4. Sockets

    • Works both locally and over the network.
    • Example: Client-server apps (like web browsers and servers).
  5. Signals

    • Simple notifications (e.g., kill -9 <pid>).

Example in Python: Pipe

from multiprocessing import Pipe, Process

def worker(conn):
    conn.send("Hello from child process")
    conn.close()

if __name__ == "__main__":
    parent_conn, child_conn = Pipe()
    p = Process(target=worker, args=(child_conn,))
    p.start()
    print(parent_conn.recv())  # Output: Hello from child process
    p.join()

Summary

  • IPC = Inter-Process Communication.
  • It lets processes exchange data and coordinate work.
  • Common tools: pipes, message queues, shared memory, sockets, signals.
  • Choice depends on speed, complexity, and use case.