系统相关
首页 > 系统相关> > python 并发编程 查看进程的pid与ppid

python 并发编程 查看进程的pid与ppid

作者:互联网

 

 

 查看进程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
'''

 

标签:__,python,pid,getpid,print,import,ppid,os,id
来源: https://www.cnblogs.com/mingerlcm/p/8986922.html