码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-06-15 23:05:51      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:def   get   并发编程   pycha   ssi   pytho   task   microsoft   ppi   

 

 

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

标签:def   get   并发编程   pycha   ssi   pytho   task   microsoft   ppi   

原文地址:https://www.cnblogs.com/mingerlcm/p/8986922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!