title: Shell command `head` with timeout
body: <p>I need to start a <code>head</code> command which shall wait for some seconds for input but if none is arriving it shall abort.  The <code>stdin</code> must not be closed (as later input shall still be available to other reading processes.</p>
  
  <p>My first approach was using a standard timeout pattern:</p>
  
  <pre><code>head &amp; pid=$! ; sleep 2; kill $pid
  </code></pre>
  
  <p>But unfortunately when sent to background the <code>head</code> won't read anything from stdin anymore.</p>
  
  <p>The next approach was to do the timeout stuff in the background:</p>
  
  <pre><code>(sleep 2; killall head) &amp;
  head
  </code></pre>
  
  <p>But this of course will kill all other running <code>head</code> processes; to find the right one seems complicated.</p>
  
  <p>Is there a better approach?</p>