After starting process, how to get parent's PID in the child?
You can use os.getppid()
:
os.getppid()
Return the parent’s process id.
Note: this works only on Unix, not on Windows. On Windows you can use os.getpid()
in the parent process and pass the pid as argument to the process you start with Popen
.
Windows support for os.getppid
was added in Python 3.2.
Use psutil
(here)
import psutil, os
psutil.Process(os.getpid()).ppid()
works both for Unix & Windows (even if os.getppid()
doesn't exist on this platform)