#include #include #include #include #include #include #include using namespace std; int main(int argc, char *argv[]) { int pipefd[2]; pid_t pid; string buf; if (pipe(pipefd) == -1) { perror("pipe"); return 1; } pid = fork(); if (pid == -1) { perror("fork"); return 1; } if (pid == 0) { /* Child reads from pipe */ close(pipefd[1]); /* Close unused write end */ dup2(pipefd[0],STDIN_FILENO); close(pipefd[0]); getline(cin, buf); while(cin) { cout << " Child here and I got the string " << buf << endl; getline(cin, buf); } } else { /* Parent writes argv[1] to pipe */ close(pipefd[0]); /* Close unused read end */ dup2(pipefd[1],STDOUT_FILENO); getline(cin, buf); while(buf != "QUIT") { cout << buf << endl; getline(cin, buf); } } return 0; }