#include #include #include #include #include int main(int argc, char** argv){ int pipefds[2]; int pipe_ret = pipe(pipefds); pid_t child_pid = fork(); if (child_pid < 0) { perror("fork error"); exit(1); } else if (child_pid == 0) { // child char* buf = "Hello parent\n"; close(pipefds[0]); printf("Child sending: %s\n", buf); write(pipefds[1], buf, strlen(buf) + 1 /* \0 terminator */); } else { // parent char buf[1024]; int child_exit_status; close(pipefds[1]); read(pipefds[0], buf, 1024); printf("Child sent:\n"); puts(buf); waitpid(child_pid, &child_exit_status, 0); } return 0; }