查看进程id pid
不需要传参数
from multiprocessing import Process import time import os def task(): print("%s is running" % os.getpid()) time.sleep(3) print("%s is done" % os.getpid()) if __name__ == "__main__": t = Process(target=task, ) t.start() print("主", os.getpid()) ''' 主 21296 29992 is running 29992 is done '''
查看父进程id ,和子进程id
from multiprocessing import Process import time import os def task(): print("%s is running,parent id is <%s>" % (os.getpid(), os.getppid())) time.sleep(3) print("%s is done,parent id is <%s>" % (os.getpid(), os.getppid())) if __name__ == "__main__": t = Process(target=task, ) t.start() print("主", os.getpid(), os.getppid()) ''' 主 30324 24252 29356 is running,parent id is <30324> 29356 is done,parent id is <30324> 24252 是pycharm pid 30324 父进程 子进程29356 '''