Why does this pid ( Popen.pid) subprocess have a different meaning from which the command is returned ps?
I noticed this when pscalled both from within python (c subprocess.call()) and from another terminal.
Here is a simple python test file:
'''
Test subprocess termination
'''
import subprocess
command = 'cat'
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
shell=True)
print('pid = %d' % proc.pid)
subprocess.call("ps -A | grep -w %s" % command,
shell=True)
proc.terminate()
proc.wait()
Typically, the pid reported psis 1 or 2 more than the reported one Popen.pid.
source
share