// Simple pipe example #include #include #include #include #include #include int main(void) { int fd[2]; pid_t pid; char buffer[10] = {0}; if( pipe(fd) < 0){ perror(NULL); exit(1); } pid = fork(); assert(pid >= 0); if (pid != 0) { // parent close(fd[0]); // writer, don't need fd[0] write(fd[1], "123456789", 10); write(fd[1], "abcdefghi", 10); close(fd[1]); } else { // child close(fd[1]); // reader, don't need fd[1] read(fd[0], buffer, sizeof(buffer)); printf("got \"%s\"\n", buffer); read(fd[0], buffer, sizeof(buffer)); printf("got \"%s\"\n", buffer); close(fd[0]); } return 0; }