import multiprocessing
import os
def run_proc(name):
print('Run child process %s (%s)...' % (name, os.getpid()))
counter = 0
for i in range(0, 1):
print("!!!weird process id: %s" % (os.getppid()))
def start():
p = None
for i in range(0, 1):
p = multiprocessing.Process(target=run_proc, args=('test',))
p.start()
if __name__ == '__main__':
print('Parent process %s.' % os.getpid())
start()
运行结果为: 父进程31476。
运行子进程测试(31488)...
我的问题是:为什么pid数在for循环中发生变化?