title: Linux non-blocking fifo (on demand logging)
body: <p>I like to log a programs output 'on demand'. Eg. the output is logged to the terminal, but another process can hook on the current output at any time. </p>
  
  <p>The classic way would be: </p>
  
  <pre><code>myprogram 2&gt;&amp;1 | tee /tmp/mylog
  </code></pre>
  
  <p>and on demand</p>
  
  <pre><code>tail /tmp/mylog
  </code></pre>
  
  <p>However, this would create a ever growing log file even if not used until the drive runs out of space. So my attempt was:</p>
  
  <pre><code>mkfifo /tmp/mylog
  myprogram 2&gt;&amp;1 | tee /tmp/mylog
  </code></pre>
  
  <p>and on demand </p>
  
  <pre><code>cat /tmp/mylog
  </code></pre>
  
  <p>Now I can read /tmp/mylog at any time. However, any output blocks the program until the /tmp/mylog is read. I like the fifo to flush any incoming data not read back. How to do that?</p>