Master the fundamental concepts of inter-process communication through this focused micro-challenge.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksPipes 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.
A pipe is a circular buffer between a writer and a reader, plus rules for what happens when one side closes. Build one that holds 8 integers.
head and writes store at tail, and both advance with (pos + 1) % 8, so the buffer wraps around.EBADF;EPIPE, because nobody can ever read it; a real process also gets SIGPIPE;EBADF;EOF, because no more data can arrive;Commands until the end of input:
write Vreadclose_writeclose_readstateFirst === Pipe Buffer cap=8 ===. Then one line per command:
| Command | Output |
|---|---|
| write | write 5 ok count=3, write 5: BLOCKED (full), write 5: EPIPE (no readers, SIGPIPE), write 5: EBADF (write end closed) |
| read | read 5 ok count=2, read: BLOCKED (empty), read: EOF (no writers), read: EBADF (read end closed) |
| close_write | write end closed |
| close_read | read end closed |
| state | state head=3 tail=1 count=6 |