Warm tip: This article is reproduced from serverfault.com, please click

uniqueness of os.getpid in multiprocessing

发布于 2020-12-04 03:22:58

I run a process distirbuted over the cores through concurrent.futures. Each of the processes has a function which ultimately calls os.getpid(). Might the IDs from os.getpid() coincide in spite of being in different concurrent.futures' branches?

Questioner
guyguyguy12345
Viewed
0
Solomon Slow 2020-12-04 11:34:16

I don't know that the meaning of the value returned by os.getpid() is well defined. I'm pretty sure that you can depend on no two running processes having the same ID, but it's very likely that after some process is terminated, it's ID eventually will be re-used.

That's what happens in most operating systems, and the implementation of os.getpid() quite likely just calls the operating system and returns the same value.