title: Replacing Shell Pipeline
body: <p>In the Python 2.7 documentation of subprocess module, I found the following snippets:</p>
  
  <pre><code>p1 = Popen(["dmesg"], stdout=PIPE)
  p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
  p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.
  output = p2.communicate()[0]
  </code></pre>
  
  <p>Source : <a href="https://docs.python.org/2/library/subprocess.html#replacing-shell-pipeline">https://docs.python.org/2/library/subprocess.html#replacing-shell-pipeline</a></p>
  
  <p>I don't understand this line : <code>p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.</code> </p>
  
  <p>Here p1.stdout is being closed. How does it allow p1 to receive a SIGPIPE if p2 exits?</p>