一、多个线程之间PID的区别
主进程跟线程的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