All pastes #945014 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-16 17:00 UTC
rendered paste body
 //This is between Child and parent  
 
   int fd2[2];
   pipe(fd2);

  //Parent begins...

   if (dup2(fd[0], 0) == -1)                /* sort is the parent */
       perror("Failed to redirect stdin of sort");
   else if ((close(fd[0]) == -1) || (close(fd[1]) == -1)) {
     perror("failed at closing");
   }
   else {
     //Output (1) of execl should go into fd2[1] not into terminal!
     if (dup2(1,fd2[1])==-1 || dup2(0,fd2[0]) == -1) {
       perror("I blame charlie");
     }
     if (execl("/usr/bin/sort", "sort", "-r", NULL) == -1) {
       perror("could not sort anything");
     }