---
title: "Interprocess communication and deadlock"
subject: "Microprocessor"
chapter: 6
key: "semester_4/microprocessor:ipc-deadlock-solution"
source: https://www.bctengineer.com/q/semester_4/microprocessor/ipc-deadlock-solution
site: BCT Engineering
---

# Interprocess communication and deadlock

Microprocessor · Chapter 6: Advanced Topics

- Asked in: 2073 Bhadra, 2+3+3 marks
- Video: [Interprocess Communication](https://www.youtube.com/watch?v=dJuYKfR8vec) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/ipc-deadlock-solution
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-6

## Question

What is interprocess communication? How does dead lock occur? How can it be solved?

## Short answer

Interprocess communication allows processes to exchange data using shared memory, messages, or semaphores. Deadlock happens when processes hold resources and wait for each other, forming a circular wait. Solutions include prevention (ordered resource acquisition), avoidance (Banker's algorithm), detection/recovery, and time-outs.

## Answer

#### Interprocess communication (IPC)

IPC is the set of mechanisms by which cooperating processes exchange data and synchronise their actions. Main methods are shared memory, message passing, pipes, semaphores and signals. It is needed for information sharing, speed-up and modularity.

#### How deadlock occurs

Deadlock occurs when processes block each other while communicating or sharing resources. It needs four conditions together: mutual exclusion, hold and wait, no preemption and circular wait.

Example: P1 locks semaphore S1 and then waits for S2; P2 locks S2 and then waits for S1. Another example: P1 waits for a message from P2, while P2 waits for a message from P1. Both are blocked for ever.

```text
 P1: wait(S1); wait(S2); ...
 P2: wait(S2); wait(S1); ...    -> circular wait
```

#### How it can be solved

1. **Prevention:** break one of the four conditions, for example, acquire locks in a fixed order (no circular wait) or request all resources at once (no hold and wait).
2. **Avoidance:** grant a request only if the system stays in a safe state (Banker's algorithm).
3. **Detection and recovery:** find a cycle in the wait-for graph, then kill a process or preempt a resource.
4. **Time-outs** on message receive or lock requests, to break message deadlocks.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is IPC?
   A. Mechanisms by which cooperating processes exchange data and synchronise
   B. A method of compressing memory
   C. A CPU scheduling algorithm
   D. A type of cache
   Answer: A. Methods include shared memory, message passing, pipes, semaphores and signals. (Key point: IPC)

2. Which scenario causes IPC deadlock?
   A. P1 locks S1 and waits for S2 while P2 locks S2 and waits for S1
   B. P1 and P2 both lock S1 one after the other
   C. P1 finishes before P2 starts
   D. P1 and P2 share a read-only file
   Answer: A. This is circular wait with hold and wait. (Key point: How deadlock occurs)

3. How does acquiring locks in a fixed order help?
   A. It removes mutual exclusion
   B. It prevents circular wait
   C. It allows preemption
   D. It detects deadlock after it happens
   Answer: B. A fixed order makes a closed chain impossible. (Key point: Prevention by ordering)

4. How can a message-receive deadlock be broken?
   A. By using time-outs on receive
   B. By removing the semaphores
   C. By increasing RAM
   D. By using more registers
   Answer: A. A time-out lets a blocked process give up. (Key point: Message deadlock)

## Related in Microprocessor

- [Parallelism, IPC deadlock and OS role](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aparallelism-deadlock-os-role) — Microprocessor, chapter 6

## Related in other subjects

- [Lock; distributed CC; deadlock situation](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alock-cc-deadlock-situation) — Distributed System, chapter 8
- [Lock, deadlock; deadlock avoidance](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alock-deadlock-avoidance) — Distributed System, chapter 8
- [PLL lock and capture range; FM demodulation](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Apll-lock-capture-fm-demod) — Communication Systems, chapter 3
