#include #include #include /* Which output is possible? 11111 33333 11111 33333 22222 44444 33333 11111 33333 11111 22222 22222 44444 22222 44444 44444 */ char buf[1024]; int main(void) { int fds[2]; pipe(fds); if (fork() == 0) { close(fds[1]); // fprintf(stderr, "11111\n"); printf("11111\n"); if (read(fds[0], buf, 1) != 1) { perror("child read"); } if (write(fds[0], buf, 1) != 1) { perror("child write"); } printf("22222\n"); exit(0); } else { close(fds[0]); // sleep(1); //fprintf(stderr, "33333\n"); printf("33333\n"); if (write(fds[1], buf, 1) != 1) { perror("parent write"); } if (read(fds[1], buf, 1) != 1) { perror("parent read"); } printf("44444\n"); exit(0); } return 0; }