title: select blocks fifo from reading
body: <p>I have a problem with read() blocking mine program while trying to read from fifo. I want my program to read from multiple file descriptors and while one has information in it, it will write it on standard output. </p>
  
  <p>I tried to use select but it seems not to work.</p>
  
  <p>main.c (there is n number of the second program)</p>
  
  <pre><code>for(i=0;i&lt;n;i++)
  {
      fd[i] = open(myfifo[i], O_RDWR);
      printf("%s\n",myfifo[i]);
  }
  while(1)
  {
          for(i=0;i&lt;n;i++)
          {
              FD_ZERO(&amp;set);
              FD_SET(fd[i], &amp;set);
              n = select(fd[i]+1, &amp;set, NULL, NULL, NULL);
              if (n &gt; 0)
              {   
                  r = read(fd[i], &amp;demon1, sizeof(demon1));
                  if(r !=-1)
                  {
                      /*READ DATA*/
                  }
              }
          }      
  }
  </code></pre>
  
  <p>second program (there is n number of this program)</p>
  
  <pre><code>void signal_handler(int signum)
  {
  if (signum == SIGUSR1)
  {
      /*STAFF*/
      mkfifo(myfifo, 0666);
      fd = open(myfifo, O_RDWR);
      write(fd, &amp;demon1 , sizeof(demon1));
      close(fd);
  }
  }
  </code></pre>
  
  <p>every program has fifo named myfifo1 ,myfifo2.. and so on. 
  Please help.</p>
  
  <p>EDIT: Now i have this:</p>
  
  <pre><code>int max_fd;
  while(1)
  {
  FD_ZERO(&amp;set);
  for(i=0;i&lt;n;i++)
  {
      FD_SET(fd[i], &amp;set);
      if (fd[i]&gt;max_fd) max_fd = fd[i];
  }
  n = select(max_fd+1, &amp;set, NULL, NULL, NULL);
  if (n != 0)
  {   
      int d;
      for (d = 0; d&lt;FD_SETSIZE; d++) 
      {
          if (FD_ISSET(d,&amp;set))
          {
              r = read(d, &amp;demon1, sizeof(demon1));
              if(r !=-1)
              {
                 /*CODE*/
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>Reads only correct on first try, later on it reads only the first filedescriptor</p>
  
  <p>apparently there is a diffrence between</p>
  
  <pre><code> //n = select(max_fd+1, &amp;set, NULL, NULL, NULL);
   //if (n != -1)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    if (select(max_fd+1, &amp;set, NULL, NULL, NULL) != -1)
  </code></pre>
  
  <p>EDIT: It seems to work only on ubuntu virutal machine.. linux mint laptop does not.</p>