Practice ยท 2 of 4
Capture Child Output Through a Pipe
CHALLENGE
Difficulty: advanced+25 XP
POSIX. Implement int capture_child(const char *cmd, char *out, size_t cap) โ fork, redirect the child's stdout into a pipe created before the fork, exec /bin/sh -c cmd, read until EOF into out (at most cap-1 bytes, NUL-terminate), waitpid, and return the child's exit code (or -1 on any setup failure).
Press Submit to check your solution.
Back to lesson: Practice: Process Machinery Drills