CS Atlas GATE 2027
Operating Systems course
0 / 58 complete

Operating Systems/Phase 1 · Processes & Threads

Lesson 1.2.2 · Item 10 of 58

Inter-process communication: shared memory, message passing and pipes

Read at your own pace. Try the questions before opening the answers.

On this page

0 · Recall Warm-up

Answer from memory first. Answers are in the Answer Vault at the bottom.

  1. What does each thread keep privately? from Lesson 1.2.1
  2. fork returns what in the child? from Lesson 1.1.2
  3. Name the five process states. from Lesson 1.1.1

1 · The Hook

In a terminal, ls | sort sends the output of one program into another. Two separate processes cooperate even though neither can see the other's memory. Inter-process communication (IPC) is how: through a shared region of memory, by passing messages, or through a pipe. GATE asks the trade-offs.

2 · Predict First

Try the questions first. Open when you are ready to check.

Two processes want to exchange 1 GB of data many times. Is it faster to copy it through the kernel each time, or to let both map the same memory region?

Make a guess in your head. The answer opens Section 3.

3 · Core Concept

Predict First — the answer

Shared memory: once set up, the data is not copied through the kernel at all. Message passing copies every message.

In plain words

Processes have separate memories. To cooperate they either share a piece of memory (like a shared whiteboard: fast, but they must take turns) or send messages through the OS (like posting letters: slower, but the OS keeps order). A pipe is a one-way message channel, like a tube from one process to another.

1. Shared memory

  • The OS maps one region into both processes' address spaces (system calls such as shmget/shmat or mmap).
  • After setup, reading and writing are ordinary memory accesses: fast, no kernel involvement.
  • The processes must synchronize themselves (Phase 3), or they will overwrite each other's data.

2. Message passing

  • Two operations: send(message) and receive(message), implemented by the kernel.
  • Direct (name the process) or indirect (through a mailbox or port).
  • Blocking (synchronous) send waits until the message is received; non-blocking send returns at once. Same for receive.
  • Simpler to use and works across machines (sockets), but each message is copied through the kernel (slower for big data).

3. Pipes

  • An ordinary pipe (pipe() system call) is unidirectional: one end for writing, one for reading; usually between a parent and a child created with fork. For two-way traffic you need two pipes.
  • A named pipe (FIFO) has a name in the file system and can connect unrelated processes.
  • A read from an empty pipe blocks; a write to a full pipe blocks.

4. The producer–consumer pattern

One process produces items, another consumes them, through a buffer of fixed size. The producer must wait when the buffer is full, the consumer when it is empty. Getting this right needs the synchronization tools of Phase 3 (Lesson 3.2.2).

4 · Visual

Shared memoryMessage passing
Speed for large datafast (no copying after setup)slower (kernel copies each message)
Kernel involvementonly at setupevery send and receive
Synchronizationprogrammer's jobbuilt into send/receive
Across machinesnoyes (sockets)
ls | sort   with an ordinary pipe

  [ ls ] --write--> [=====pipe=====] --read--> [ sort ]
                one direction only

5 · Worked Examples

Example 1 Easy

How many ordinary pipes are needed for two-way communication between parent and child?

Solution

2 (pipes are one-way).

Example 2 Medium

Which IPC method needs explicit synchronization by the programmer?

Solution

Shared memory.

Example 3 GATE

A process does a blocking receive on an empty mailbox. What happens?

Solution

It waits (blocks) until a message arrives.

6 · GATE Traps

  • Ordinary pipes are one-way.
  • Shared memory is fast but not automatically synchronized.
  • Message passing copies data through the kernel each time.
  • Blocking send waits for the receiver; non-blocking returns immediately.

7 · Memory Hook

"Shared memory: fast whiteboard, take turns. Messages: letters through the OS."

8 · Connect the Dots

Phase 1 is complete: processes, fork, threads and IPC. Phase 2 answers the question the short-term scheduler faces thousands of times a second: which ready process runs next?

9 · Self-Test

GATE format. Try every question before opening the vault.

Q1 · MCQ · 1 mark(s) — Speed

For exchanging large amounts of data between two processes on one machine, the fastest method after setup is usually:

  1. (A) message passing
  2. (B) sockets
  3. (C) shared memory
  4. (D) ordinary pipes

Q2 · MCQ · 1 mark(s) — Pipes

An ordinary (anonymous) pipe is:

  1. (A) stored permanently on disk
  2. (B) usable between any two unrelated processes
  3. (C) bidirectional
  4. (D) unidirectional

Q3 · MSQ · 2 mark(s) — Message passing

Which are true of message passing?

  1. (A) It never blocks.
  2. (B) It is often simpler to program correctly than shared memory.
  3. (C) The kernel is involved in each send and receive.
  4. (D) It can work between processes on different machines.

Q4 · NAT · 1 mark(s) — Pipes

A parent wants two-way communication with each of its 3 children using ordinary pipes. Minimum number of pipes?

Numerical answer: ________

Q5 · MCQ · 1 mark(s) — Producer–consumer

In the bounded-buffer producer–consumer problem, the producer must wait when:

  1. (A) the buffer is empty
  2. (B) the buffer is full
  3. (C) the consumer is running
  4. (D) never

10 · Rule Card

  • Shared memory: map a common region; fast; programmer synchronizes.
  • Message passing: send/receive via the kernel; direct or indirect (mailbox); blocking or non-blocking; works across machines; copies data.
  • Ordinary pipe: one-way, parent–child; named pipe (FIFO) for unrelated processes; two-way needs two pipes.
  • Producer waits when the buffer is full; consumer waits when empty.

11 · Concept Ledger

Unlocked in this lesson. From here on, these terms may be used.

inter-process communicationshared memorymessage passingsend and receivedirect and indirect communicationmailboxesblocking and non-blocking operationsordinary pipesnamed pipes (FIFOs)producer–consumer with a bounded buffer

12 · Answer Vault

Try the questions first. Open when you are ready to check.

🔐 Open the Answer Vault

Recall Warm-up

  1. Stack, registers, program counter.
  2. New, ready, running, waiting, terminated.

Self-Test

Q1 Answer: (C) · 1 mark(s)

No copying through the kernel.

  • (A) is wrong: Copies every message.
  • (B) is wrong: Copies through the kernel.
  • (D) is wrong: Copies through the kernel.

Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes

Q2 Answer: (D) · 1 mark(s)

Write end and read end.

  • (A) is wrong: It lives in memory.
  • (B) is wrong: Usually parent–child; named pipes connect unrelated ones.
  • (C) is wrong: Two pipes are needed for two-way traffic.

Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes

Q3 Answer: (B) (C) (D) · 2 mark(s)

Blocking variants exist.

  • (A) is wrong: Blocking send/receive wait.

Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes

Q4 Answer: 6 · 1 mark(s)

Two per child.

Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes

Q5 Answer: (B) · 1 mark(s)

No space to put an item.

  • (A) is wrong: That is when the consumer waits.
  • (C) is wrong: Not by itself a reason.
  • (D) is wrong: It must wait when full.

Re-read: Lesson 1.2.2 — Inter-process communication: shared memory, message passing and pipes

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.