title: Bash: how to listen the output of another running program
body: <p>Say I have two bash scripts (<code>p1.sh</code> and <code>p2.sh</code>), representing two programs:</p>
  <pre><code>#!/bin/bash
  
  echo &quot;hello&quot;
  sleep 10s
  echo &quot;good morning&quot;
  sleep 10s
  echo &quot;goodbye !!&quot;
  </code></pre>
  <p>And <code>p2.sh</code>:</p>
  <pre><code>#!/bin/bash
  
  # listen to the output of p1's program
  # if p1 gives &quot;goodbye !!&quot; output, echo &quot;p1 said goodbye!&quot;
  </code></pre>
  <p>The workflow is:</p>
  <ol>
  <li>Run <code>p1.sh</code></li>
  <li>Get the pid of the <code>p1</code> program</li>
  <li>Let <code>p2.sh</code> listen to the <code>p1</code> process's output (instead of calling <code>p1.sh</code> inside of <code>p2.sh</code>), and judge <code>p1</code>'s output.</li>
  </ol>
  <p>How to realize it? Thanks!</p>