PID

Windows系统下的进程PID
image.png

  1. from multiprocessing import Process
  2. import time, os
  3. def task():
  4. print('%s is running,parent id is <%s>' % (os.getpid(), os.getppid()))
  5. time.sleep(3)
  6. print('%s is done,parent id is <%s>' % (os.getpid(), os.getppid()))
  7. if __name__ == '__main__':
  8. p = Process(target=task, )
  9. p.start()
  10. print('主', os.getpid(), os.getppid())

进程ID.gif
观察:父进程执行完后,父进程等待子进程执行完,程序才结束。