Master the fundamental concepts of inter-process communication through this focused micro-challenge.
Pipes connect a writer fd to a reader fd through a kernel buffer implemented as a ring. Writes block when full; reads block when empty. Shell pipelines are just pipe pairs between processes.
Track:
For example, capacity 4096 with 5000 byte write blocks after 4096 bytes until reader consumes data.
cLoading…
This circular buffer with blocking read/write is a near-exact model of the real Linux kernel pipe implementation in fs/pipe.c, which is exactly what makes cat file | grep pattern work without either program blocking forever. Getting the close-both-ends discipline wrong here reproduces a real, common bug: forgetting to close the unused pipe end in a forked child means the reader never sees EOF and hangs indefinitely, a classic shell-implementation gotcha.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will implement blocking read/write on a userspace ring buffer with mutex/cond or your mini-kernel pipe. This exercise requires demonstrating producer-consumer throughput without busy waiting.
Implement pipe with circular buffer and blocking semantics.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github