All pastes #944452 Raw Edit

Someone

public text v1 · immutable
·published 2008-03-16 02:34 UTC
rendered paste body
int main(void) {
   pid_t childpid;
   int fd[2];
   if (( pipe(fd) == -1) || ((childpid = fork() ) == -1)) {             /* setup the pipeline*/
      perror("Failed to setup pipeline");
      return 1;
   }
   if (childpid==0) {                                  /* ls is the child */

     if (dup2(fd[1] , 1) == -1)
         perror("Failed to redirect stdout of ls");
      else if (( close(fd[1]) == -1) || ( close(fd[0]) == -1))
         perror("Failed to close extra pipe descriptors on ls");
    else {
        printf("HI\n");
      }
      return 1;
   }
   if (dup2(fd[0], 0) == -1)               /* word count is the parent */
       perror("Failed to redirect stdin of sort");
   else if ((close(fd[1]) == -1) || (close(fd[0]) == -1))
       perror("Failed to close extra pipe file descriptors on sort");
   else {
     execl("/usr/bin/wc", "-cl", NULL);
     perror("Failed to exec word count");
   }