title: Return value of system() function call in C++, used to run a Python program
body: <p>I am working on Linux with code that makes a <code>system()</code> call to run a python program. I am interested in the value returned by this function call to understand how the python program execution went.</p>
  
  <p>So far, I have found 3 results:</p>
  
  <ul>
  <li><p>When the python process completes successfully, value returned by system() is 0</p></li>
  <li><p>When the python process is killed mid-execution (using <code>kill -9 pid</code>), value returned by system() is 9</p></li>
  <li><p>When the python process fails on its own due to incorrect parameters, value returned by system() is 512</p></li>
  </ul>
  
  <p>This does not fit with what I've read about <a href="http://linux.die.net/man/3/system" rel="noreferrer">system()</a> function.</p>
  
  <p>Furthermore, the code for the python program being invoked shows that it exits with <code>sys.exit(2)</code> when any error is encountered, and <code>sys.exit(0)</code> when execution completes successfully.</p>
  
  <p>Could anyone relate these two? Am I interpreting the return value in a wrong manner? Is there some Linux processing involved that takes the argument of the <code>sys.exit()</code> function of the python program and returns value of <code>system()</code> based on it?</p>