主进程跟线程的pid是一样的

from threading import Thread
from multiprocessing import Process
import os

def task():
    print('%s is running' %os.getpid())

if __name__ == '__main__':
    t1=Thread(target=task,)
    t2=Thread(target=task,)
    t1.start()
    t2.start()
    print('主',os.getpid())
输出:
6700 is running
6700 is running
主 6700

二、多个进程PID的区别

多个进程的PID完全不一样

from threading import Thread
from multiprocessing import Process
import os

def task():
    print('%s is running' %os.getpid())

if __name__ == '__main__':
    t1=Process(target=task,)
    t2=Process(target=task,)
    t1.start()
    t2.start()
    print('主',os.getpid())



输出:
主 2040
7104 is running
2768 is running

  

  

相关文章:

  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-06-03
  • 2021-11-17
  • 2021-06-10
  • 2022-12-23
  • 2022-02-19
猜你喜欢
  • 2021-10-24
  • 2021-11-05
  • 2021-09-16
  • 2021-05-16
  • 2022-12-23
  • 2021-11-27
相关资源
相似解决方案