Master the fundamental concepts of inter-process communication through this focused micro-challenge.
Unix domain sockets (AF_UNIX) move bytes between processes on one machine with stream or datagram semantics. Paths bind to filesystem names; SCM_RIGHTS can pass file descriptors.
Server steps:
socket(AF_UNIX, SOCK_STREAM, 0)bind to path, listen, acceptread/write on connected fdFor example, /tmp/app.sock may carry RPC requests while TCP stack stays untouched, lowering latency for local services.
AF_UNIX sockets are exactly how the Docker daemon exposes its API at /var/run/docker.sock, how X11 clients talk to the display server, and how systemd's D-Bus implementation passes messages locally, all chosen specifically because filesystem permissions on the socket path double as an access-control mechanism. The SCM_RIGHTS file-descriptor-passing feature mentioned here is a real production technique: privilege-separated daemons like OpenSSH use it to hand a already-opened, permission-checked fd to an unprivileged worker process.
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 echo server and client with stream sockets and cleanup the bound path on exit. This exercise requires handling EADDRINUSE when stale socket files remain.
Implement Unix domain socket server and client.
Requirements:
Client:
Test:
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