title: How can select() wait on regular file descriptors (non-sockets)?
body: <p>This is the code sample from "man select" plus a few lines to read an actual file which is being written to.  I suspected that when the <code>./myfile.txt</code> is written to, <code>select</code> would return that it can now read from that fd.  But what happens is that select constantly returns in the while loop so long as the txt file exists. I want it to only return when new data is written to the end of the file. I thought that is how it should work.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  
  int
  main(void)
  {
      fd_set rfds;
      struct timeval tv;
      int retval;
  
      int fd_file = open("/home/myfile.txt", O_RDONLY);
  
     /* Watch stdin (fd 0) to see when it has input. */
      FD_ZERO(&amp;rfds);
      FD_SET(0, &amp;rfds);
      FD_SET(fd_file, &amp;rfds);
  
     /* Wait up to five seconds. */
      tv.tv_sec = 5;
      tv.tv_usec = 0;
  
     while (1)
     {
       retval = select(fd_file+1, &amp;rfds, NULL, NULL, &amp;tv);
       /* Don't rely on the value of tv now! */
  
       if (retval == -1)
          perror("select()");
       else if (retval)
          printf("Data is available now.\n");
          /* FD_ISSET(0, &amp;rfds) will be true. */
       else
          printf("No data within five seconds.\n");
     }
  
     exit(EXIT_SUCCESS);
  }
  </code></pre>