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.