title: Why does os.kill(pid, 0) return None although process has terminated?
body: <p>This issue is related to <a href="https://stackoverflow.com/a/13402639/1125413">this answer</a> for one of my other questions. I was told in this answer that one can use <code>os.kill(pid, 0)</code> to check whether a subprocess has terminated. If it is still running, <code>None</code> is returned. If it has terminated, an <code>OSError</code> is raised. This has been working fine so far, but now I'm in a situation in which <code>os.kill(pid, 0)</code> still returns <code>None</code> although the subprocess has already terminated. The process id was 82430 and in the activity monitor on OSX I cannot find a process with this ID anymore. However, when I open a Python shell and enter <code>os.kill(82430, 0)</code>, then it still returns <code>None</code>. I don't understand that.</p>
  
  <p>Precisely, I check the status of the subprocess periodically in a Django view via an Ajax GET request as shown above.</p>
  
  <p><strong>Django view on server side</strong></p>
  
  <pre><code>def monitor_process(request):
      response_data = {}
  
      try:
          os.kill(int(request.GET['process_id']), 0)
          response_data['process_status'] = 'running'
      except OSError:
          response_data['process_status'] = 'finished'
  
      return HttpResponse(json.dumps(response_data), mimetype='application/json')
  </code></pre>
  
  <p><strong>Ajax call on client side</strong></p>
  
  <pre><code>var monitorProcess = function(processId) {
  
      $.ajax({
          dataType: 'json',
          type: 'GET',
          url: '/monitor_process/',
          data: {'process_id': processId},
          success: function(response) {
  
              if (response.process_status == 'running') {
                  // Only this branch is always executed
  
                  // ...
              }
  
              else if (response.process_status == 'finished') {
                  // This branch never gets executed
  
                  // Stop checking for process status
                  // The periodic check was started by 
                  // window.setInterval in a different Ajax call
                  clearInterval(monitorProcessId);
  
                  // ...
  
              }
          }
      });
  }; 
  </code></pre>
  
  <p>Although the process stops and disappears in the activity monitor at some point, <code>os.kill()</code> apparently doesn't recognize it. Why is this the case? Thank you very much!</p>