title: Linux: check if file descriptor is available for reading
body: <p>Considering the following example, emulating a command which gives output after 10 seconds: <code>exec 5&lt; &lt;(sleep 10; pwd)</code></p>
  
  <p>In Solaris, if I check the file descriptor earlier than 10 seconds, I can see that it has a size of 0 and this tells me that it hasn't been populated with data yet. I can simply check every second until the file test condition is met (different from 0) and then pull the data:</p>
  
  <pre><code>while true; do
      if [[ -s /proc/$$/fd/5 ]]; then
          variable=$(cat &lt;&amp;5)
          break
      fi
      sleep 1
  done
  </code></pre>
  
  <p>But in Linux I can't do this (RedHat, Debian etc). All file descriptors appear with a size of 64 bytes no matter if they hold data or not. For various commands that will take a variable amount of time to dump their output, I will not know when I should read the file descriptor. No, I don't want to just wait for <code>cat &lt;&amp;5</code> to finish, I need to know when I should perform the <code>cat</code> in the first place. Because I am using this mechanism to issue simultaneous commands and assign their output to corresponding file descriptors. As mentioned already, this works great in Solaris.</p>