title: How to get the PID of a process in a pipeline
body: <p>Consider the following simplified example:</p>
  
  <pre>
  <code>
  my_prog|awk '...' > output.csv &
  my_pid="$!" #Gives the PID for awk instead of for my_prog
  sleep 10
  kill $my_pid #my_prog still has data in its buffer that awk never saw. Data is lost!
  </code>
  </pre>
  
  <p>In bash, <code>$my_pid</code> points to the PID for <code>awk</code>.  However, I need the PID for <code>my_prog</code>.  If I kill <code>awk</code>, <code>my_prog</code> does not know to flush it's output buffer and data is lost.  So, how would one obtain the PID for <code>my_prog</code>?  Note that <code>ps aux|grep my_prog</code> will not work since there may be several <code>my_prog</code>'s going.</p>
  
  <p>NOTE:  changed <code>cat</code> to <code>awk '...'</code> to help clarify what I need.</p>