linux-sysprog · advanced · ~15 min
`pipe`, `read`, `write`, and the discipline of closing every fd you open.
Implement int pipe_roundtrip(const char *msg, char *out, size_t out_sz) that creates a pipe, writes msg to its write end, reads from its read end into out (NUL-terminating), closes everything, and returns 0 on success.
#include <unistd.h>
#include <string.h>
#include <stddef.h>
int pipe_roundtrip(const char *msg, char *out, size_t out_sz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.