#include #include #include int main(int argc, char **argv) { int pipe_ends [2]; if (pipe(pipe_ends) == -1) perror("pipe"), exit(1); pid_t child = fork(); if (child == -1) perror("fork"), exit(1); if (child == 0) { // the child char msg [] = { "Hi\n" }; close(pipe_ends[0]); if (write(pipe_ends[1], msg, sizeof msg - 1) == -1) perror("write"); } else { // the parent char pipe_buf[128]; close(pipe_ends[1]); size_t n; while ((n = read(pipe_ends[0], pipe_buf, sizeof pipe_buf)) > 0) if (write(1, pipe_buf, n) != n) perror("write"); } }