100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is Inter-Process Communication (IPC)?

Learn what IPC is — pipes, message queues, shared memory, and sockets — with examples and operating systems interview questions answered.

mediumQ17 of 224 in Operating Systems Est. time: 6 minsLast updated:
Open Code Lab

Expected Interview Answer

Inter-process communication (IPC) is the set of mechanisms an operating system provides for separate processes — each with its own isolated address space — to exchange data and coordinate their actions.

Because processes cannot directly read or write each other’s memory, the kernel mediates communication through channels such as pipes and named pipes for byte streams between related or unrelated processes, message queues for structured discrete messages, shared memory for the fastest data exchange via a jointly mapped region, and sockets for communication across machines as well as locally. Shared memory is the fastest option but requires explicit synchronization, typically with semaphores, since the OS does not serialize access for you. Choosing the right IPC mechanism trades off speed, complexity, and whether the communicating processes are on the same host.

  • Lets isolated processes exchange data safely
  • Enables coordination between cooperating processes
  • Multiple mechanisms trade off speed vs simplicity vs reach
  • Shared memory plus semaphores gives the highest throughput

AI Mentor Explanation

IPC is like two separate teams in adjoining stadiums needing to exchange information despite having no direct line of sight. A runner physically carrying scorecards between grounds is like a pipe — simple but sequential. Radio broadcast to both grounds is like shared memory — instant but needs an agreed protocol so both sides do not talk over each other. Different exchange methods suit different needs, exactly like choosing between pipes, queues, and shared memory in an OS.

Step-by-Step Explanation

  1. Step 1

    Isolation problem

    Processes have separate address spaces, so they cannot directly read or write each other’s memory.

  2. Step 2

    Kernel-mediated channel

    The OS provides a channel — pipe, message queue, shared memory, or socket — through which data can pass.

  3. Step 3

    Data exchange

    Processes write to and read from the channel using the appropriate system calls (e.g. write/read, msgsnd/msgrcv, shmat).

  4. Step 4

    Synchronization

    For shared memory in particular, semaphores or mutexes coordinate access since the OS does not serialize it automatically.

What Interviewer Expects

  • Understanding that processes are isolated by default
  • Naming multiple IPC mechanisms: pipes, message queues, shared memory, sockets
  • Knowing shared memory is fastest but needs explicit synchronization
  • Awareness of local vs networked IPC (sockets)

Common Mistakes

  • Saying threads and processes use the same IPC mechanisms
  • Forgetting shared memory needs synchronization primitives
  • Naming only one IPC mechanism instead of comparing several
  • Confusing pipes (byte stream) with message queues (discrete messages)

Best Answer (HR Friendly)

IPC is how completely separate programs running on a computer share data or coordinate with each other, since they normally cannot see into each other’s memory. The operating system offers several channels for this — like a pipe for a simple stream of data, or shared memory for very fast exchange — and the choice depends on how much speed versus simplicity is needed.

Code Example

Simple pipe IPC between parent and child
#include <unistd.h>
#include <string.h>

int main(void) {
    int fd[2];
    pipe(fd);                     /* fd[0] = read end, fd[1] = write end */

    if (fork() == 0) {
        close(fd[0]);
        write(fd[1], "hello", 5); /* child writes into the pipe */
        close(fd[1]);
    } else {
        close(fd[1]);
        char buf[6] = {0};
        read(fd[0], buf, 5);      /* parent reads from the pipe */
        close(fd[0]);
    }
    return 0;
}

Follow-up Questions

  • What is the difference between a pipe and a named pipe (FIFO)?
  • Why does shared memory need semaphores?
  • How do message queues differ from pipes?
  • When would you choose sockets over shared memory for IPC?

MCQ Practice

1. Why do processes need IPC mechanisms at all?

Each process has its own private address space, so the kernel must mediate any data exchange between them.

2. Which IPC mechanism is generally the fastest but requires explicit synchronization?

Shared memory avoids copying data through the kernel, making it fastest, but processes must synchronize access themselves.

3. Which IPC mechanism naturally supports communication across separate machines?

Sockets work over a network as well as locally, unlike pipes and shared memory which are confined to one host.

Flash Cards

What is IPC?Mechanisms that let isolated processes exchange data and coordinate actions.

Fastest IPC mechanism?Shared memory — but it needs explicit synchronization like semaphores.

Name three IPC mechanisms.Pipes, message queues, and shared memory (also sockets).

Which IPC works across machines?Sockets — pipes and shared memory are limited to one host.

1 / 4

Continue Learning