Reputation: 831
I need to get the real process ID IN the spawned child as seen by the parent in my example. Right now os.getpgid(0) just returns the parents process ID because its inherited which is correct. But in the parent the child process ID is different. This is just a simple example but I will implement it in another program:
#!/usr/bin/python3
import os
mypid = os.getpgid(0)
print ("My pid is %s" % mypid)
childpid = os.spawnv(os.P_NOWAIT, "./spawn2.py", ["foo", "bar"])
print ("I forked to spawn2 with pid %s" % childpid)
#!/usr/bin/python3
import os
pid = os.getpgid(0)
print ("I'm spawn2")
print ("My pid is %s" % pid)
The output looks like this, but I want the spawned child to say its pid is 1658:
pi@oriondev1:~/git-repos/zguide/examples/Python $ ./spawn1.py
My pid is 1657
I forked to spawn2 with pid 1658
pi@oriondev1:~/git-repos/zguide/examples/Python $ I'm spawn2
My pid is 1657
Upvotes: 0
Views: 279
Reputation: 831
Duh. The answer is use os.getpid() I was just confused. Thx for the nudge @Jasper.
Upvotes: 1