I am in Windows and Suppose I have a main python code that calls python interpreter in command line to execute another python script ,say test.py .
So test.py is exe
It all depends on how you're launching the second process.
If you're using os.system
or similar, that call won't report back anything useful about the child process's pid. One option is to have your 2nd script communicate the result of os.getpid()
back to the original process via stdin/stdout, or write it to a predetermined file location. Another alternative is to use the third-party psutil library to figure out which process it is.
On the other hand, if you're using the subprocess
module to launch the script, the resulting "popen" object has an attribute popen.pid which will give you the process id.