FIT2100 Chap.11 Pipes, Shared Memory and Sockets
Pipes, Shared Memory and Sockets
IPC channels differ in storage, naming and guarantees. Pipes are kernel-managed byte streams with read and write ends. Unnamed pipes naturally connect related processes that inherit descriptors, while named pipes provide a persistent namespace entry.
Shared memory maps common pages into separate address spaces and requires explicit coordination for conflicting access.
Sockets represent addressed communication endpoints. A stream server creates, binds and listens on a socket, then accepts a separate connected descriptor. A client creates an endpoint and connects.
Reliable byte streams preserve byte order but not application record boundaries, so programs must frame messages and handle partial reads and writes.
What this chapter covers
- 01
Unnamed pipes
- 02
Named pipes
- 03
Descriptor inheritance
- 04
Blocking and end-of-file
- 05
Shared-memory mappings
- 06
Socket domains and types
- 07
Client and server sequence
- 08
Stream framing
Worked example · free
Diagnose a pipe that never reaches end-of-file
- +2Pipe end-of-file requires an empty buffer and no remaining open write references, not merely closure by the intended writer.
- +2The child's unused inherited write descriptor keeps a writer reference alive, so the kernel cannot yet report end-of-file.
- +2Close the read end in the writer and the write end in the reader immediately after process creation, then close active ends after use.
Key terms
- Unnamed Pipe
- A kernel byte stream usually shared through inherited read and write descriptors between related processes.
- Named Pipe
- A pipe represented by a filesystem name so unrelated local processes can open the endpoints.
- Shared Segment
- A memory region mapped into more than one process address space.
- Socket
- An addressed communication endpoint used by local or network protocols.
- Listening Socket
- A server endpoint that accepts incoming connection requests and produces connected descriptors.
- Message Framing
- An application rule that identifies record boundaries in a byte stream, such as a length prefix or delimiter.
Pipes, Shared Memory and Sockets FAQ
When does an empty pipe return end-of-file?
The buffer must be empty and every write descriptor referring to that pipe must be closed. One inherited write end held by the reader is enough to prevent the kernel from concluding that no more bytes can arrive.
Why can shared memory be faster than messages?
After mapping, processes access the same pages without copying every payload through a kernel message buffer. Setup and page management still exist, and the programs become responsible for synchronising readers and writers.
Why does accept return another socket?
The listening socket remains available for new connection requests. The returned connected descriptor represents one client conversation. Separating them lets a server accept further clients while existing connections exchange data independently.
Can one send equal one message on a stream?
No. A stream preserves ordered bytes but may split or combine application writes across reads. The application must define record framing and loop over partial operations until the required byte count is handled.
Assessment move
Sketch descriptor ownership after each process-creation step and close unused ends on paper before writing code. Compare pipe, shared memory and socket designs on host boundary, process relationship, data shape and synchronisation. For stream sockets, practise length-prefixed framing with partial reads and writes.
In a demonstration, deliberately fragment a transfer or keep an extra descriptor open, then explain the observed blocking through kernel reference counts. Make descriptor diagrams that distinguish process-local numbers from references to one kernel object. Start immediately after pipe creation, duplicate the table after process creation and cross out every close.
Predict read blocking, write blocking, end-of-file and broken-pipe behaviour from the remaining references. Include a case where the reader accidentally retains a write end. For shared memory, design a small layout with an ownership flag or queue indices and name the semaphore or mutex rule that makes each field valid; ordinary loads and stores do not supply message boundaries.
For sockets, rehearse the separate listening and connected descriptors on the server and the creation and connect sequence on the client. Build a length-prefixed protocol with a fixed field width, network byte order, maximum permitted length and loops for partial input or output. Test a zero-length record, early peer close and a length larger than the limit.
Compare stream and datagram claims without transferring guarantees between them. During demonstrations, log descriptor creation and closure as well as payload bytes. Deliberately split one logical record across several operations and prove that framing reconstructs it.
Explain observed completion at three levels: bytes accepted locally, bytes received by the peer and application-level processing, which are not equivalent events.
Working through Pipes, Shared Memory and Sockets in FIT2100? Sia is AskSia’s AI Computer Science tutor — ask any FIT2100 Pipes, Shared Memory and Sockets question and get a clear, step-by-step explanation grounded in how FIT2100 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.