Interprocess Communication
Table of Contents + −
You learned that processes each have their own private memory that no other process can touch. That isolation keeps them safe, but it creates a problem:
- If two processes can’t see each other’s memory, how do they share data or work together?
They can’t just reach into each other’s memory like threads do. They need special, agreed-upon channels to pass messages. Those channels are called interprocess communication, or IPC. Let’s look at the common ways processes talk.
🎯 Why Processes Need Special Channels
Remember the key fact: processes are isolated on purpose. Process A cannot read Process B’s variables. So to cooperate, they need a channel that both can reach, set up through the operating system.
Think of two people in separate locked rooms. They can’t just hand each other a note. They need an agreed way: a slot in the wall, a phone line, a shared mailbox. IPC is that set of agreed channels. There are a few common ones, each suited to a different situation.
📁 Files
The simplest channel is a shared file. One process writes data to a file, and another process reads it.
- It’s easy to understand, and the data stays around even after a process stops.
- But it’s slow, because reading and writing to disk takes time.
- And you have to be careful if both write at once, or they can mess up each other’s data.
So files work well when processes don’t need to talk fast, and when keeping the data afterward is useful, like one program writing a report that another reads later.
🔔 Signals
A signal is a tiny nudge sent from one process to another to say “something happened.” It doesn’t carry real data, just a simple notification.
- It’s great for quick alerts, like “please stop” or “reload your settings.”
- But it carries almost no information. It’s a tap on the shoulder, not a conversation.
You’ve actually used signals without knowing. When you press Ctrl+C to stop a program, that sends it a signal to quit.
Signals are nudges, not messages
A signal can’t send a paragraph of data. It just tells a process that some event happened, and the process decides how to react. For real data, you need one of the other methods.
🔌 Sockets
A socket is a two-way channel that lets processes send data back and forth, even if they’re on different computers across a network.
- It’s flexible and powerful. The same idea works for two processes on one machine or two servers across the world.
- This is how most networked apps talk, like your browser talking to a web server.
- It’s a bit more work to set up than a file or a signal.
Sockets are the backbone of networked communication. Any time two programs talk over a network, sockets are doing the work underneath.
🚰 Pipes
A pipe connects the output of one process to the input of another, so data flows straight from one into the next.
- Data written by the first process comes out the other end for the second process to read.
- It’s a clean one-way flow, perfect for chaining steps together.
You’ve seen pipes if you’ve used a command line. Here’s the classic example, with a lead-in to what it does. This command sends the output of one program straight into another.
# The output of "cat log.txt" flows into "grep error"cat log.txt | grep "error"Reading that: the | symbol is a pipe. The first program lists the file, and instead of printing it, that output flows directly into the second program, which filters for errors. One process feeds the next.
📊 The Four Methods Compared
Here’s the quick view.
| Method | Carries | Best for |
|---|---|---|
| File | Lots of data, stays around | Slow sharing, keeping data after |
| Signal | Just a notification | Quick alerts like “stop” |
| Socket | Two-way data, even over a network | Networked apps, flexible talk |
| Pipe | A one-way stream of data | Chaining one process into the next |
⚠️ Common Mistakes and Misconceptions
A few things to keep straight:
- “Processes can just share variables like threads.” No. Processes have isolated memory, so they must use an IPC channel. That’s the whole reason IPC exists.
- “Signals can send any data.” They can’t. A signal is just a small notification. For real data, use a pipe, socket, or file.
- “Sockets only work across a network.” They work between two processes on the same machine too. The network is just one place they’re used.
🧩 What You’ve Learned
Nice work. Here’s the recap:
- ✅ Processes have isolated memory, so they need special channels (IPC) to talk.
- ✅ Files share data slowly and keep it around afterward.
- ✅ Signals are tiny notifications, like “please stop,” and carry no real data.
- ✅ Sockets are flexible two-way channels that work even across a network.
- ✅ Pipes send a one-way stream from one process straight into another.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
Why do processes need special channels to communicate?
Why: Processes have their own private memory, so they can't reach into each other like threads can. IPC channels let them pass data.
- 2
What does a signal carry?
Why: A signal is a nudge, like 'please stop.' It carries no real data. For data, you use a pipe, socket, or file.
- 3
Which method is a two-way channel that also works across a network?
Why: Sockets let processes send data back and forth, whether on the same machine or across the world. It's how networked apps talk.
- 4
What does a pipe do?
Why: A pipe connects one process's output to another's input, a clean one-way flow. The command-line | is a pipe.
🚀 What’s Next?
You know how separate processes talk. Now let’s see how threads stay safe while sharing memory.
- Locks & Synchronization shows how threads avoid clashing over shared data.
- Processes vs Threads is the foundation this builds on.
Get these down and you’ll understand how parts of a system coordinate safely.