title: Python subprocess : in which case a segfault program returns -11 or 139?
body: <p>I'm using Python 3.7 and <code>subprocess</code> library.</p>
  
  <p>I have a binary <code>my_prog</code> which crashes with segfault :</p>
  
  <pre><code>$&gt; ./my_prog
  [1]    9328 segmentation fault  ./my_prog
  </code></pre>
  
  <p>In my script <code>main.py</code>, I have these lines of code :</p>
  
  <pre><code>try:
      output = subprocess.check_output(['./my_prog'], shell=True, stderr=subprocess.STDOUT)
  except subprocess.CalledProcessError as exc:
      print(exc.returncode)
      print(exc.output)
  </code></pre>
  
  <p>In this case, I get </p>
  
  <pre><code>$&gt; python3 main.py
  -11
  b''
  </code></pre>
  
  <p>Ok, subprocess catches the signal SIGSEGV.<br>
  Ok, no output. Why not.</p>
  
  <p>But, if I want the same program to read on stdin, I have to modify my line in <code>main.py</code> (the file "text.txt" exists):</p>
  
  <pre><code>output = subprocess.check_output(['./my_prog &lt; text.txt'], shell=True, stderr=subprocess.STDOUT)
  </code></pre>
  
  <p>And in this case I get :</p>
  
  <pre><code>$&gt; python3 main.py
  139
  b'/bin/sh: line 1: 17235 Segmentation fault: 11  ./my_prog &lt; text.txt\n'
  </code></pre>
  
  <p>I know it's 11 + 128, that means SIGSEGV too.<br>
  And, now, I have an output !</p>
  
  <p>Even if 139 and -11 mean the same, why the returncode changes in these 2 different situations ? And why is there no output in the first case ?</p>
  
  <p>Thanks :)</p>
  
  <p><strong>EDIT</strong> :<br>
  Add the difference on output issue.</p>