title: Troubles with a pipe and a fork
body: <p>I'm making a program that search files and sends it's results to other commands, like a pipe. ls | sort
  When I run the program nothing happens.The problem I think is that the child's waits for the parent to stop writting in the SO buffer for starting the reading. 
  This is what it sends to stdout and what the pipe should send to the other command. </p>
  
  <pre><code>    troneras@troneras-VirtualBox:~/Escritorio/busca.2012$ ./busca . -n . -print
      ./permisos.txt
      ./busca2.c
      ./mmap.pdf
      ./busca3.c~
      ./cuadernoso4.2011b.pdf
      ./busca.c~
      ./busca.c
      ./busca2.c~
      ./busca3.c
  </code></pre>
  
  <p>I don't understand what the problem is.</p>
  
  <hr>
  
  <pre><code>     if(!strcmp(argv[4],"-pipe"))
   {
  int pipefd[2];
  int pid,dummi;
  
  if (pipe(pipefd)&lt;0){
     perror("pipe");
     exit(1);
  }
  
  pid = fork();
  
  if (pid&lt;0){
     perror("fork");
     exit(1); 
  }
  if (pid == 0){//Child process    
     close(pipefd[1]);//The child is only reading from the pipe
     if(dup2(pipefd[0],0)!=0){perror("dup2");exit(1);}
     close(pipefd[0]);
  
         char *argumentos[argc-4];
     int j;
     for (j=5;j&lt;argc;j++){
        argumentos[j-5]=argv[j];   
     }         
     argumentos[j-5]= NULL;    
  
     execvp(argv[5],argumentos);
     perror("execve: ");
  
  }else{ //parent        
     close(pipefd[0]);
     if(dup2(pipefd[1],1)!=1){perror("dup2");exit(1);}
     close(pipefd[1]);
  
     while(count--){
        if(strcmp(files[count]-&gt;d_name,".") &amp;&amp; strcmp(files[count]-&gt;d_name,"..")){               
           printf("%s/%s\n",argv[1],files[count]-&gt;d_name);                       
        free(files[count]);
     }
  
         wait(&amp;dummi);
  }
  
   }//end pipe                 
   free(files);
  </code></pre>