// Put it all together. Use fork, pipe, exec, and cout! #include #include using namespace std; int main(void) { int i; int p[2]; //our pipe int pid; //create the pipe pipe(p); //fork the process pid = fork(); if(pid) { //use the write side of the pipe as stdout dup2(p[1], STDOUT_FILENO); close(p[0]); //count to 1000 for(i=0; i < 1000; i++) cout << i << endl; } else { //use the read side of the pipe as stdin dup2(p[0], STDIN_FILENO); close(p[1]); //run less execlp("cat", "cat"); } return 0; }