[root@localhost ~]# cat twoproces.py #!/usr/bin/env python from multiprocessing import Process import os def output(): print "My pid is :%d\n" % os.getpid() print "My parent is:%d\n" % os.getppid() def main(): p=Process(target=output) p.start() print "I am parent %d\n" % os.getpid() if __name__=="__main__": main()
[root@localhost ~]# ./twoproces.py I am parent 7656 My pid is :7660 My parent is:7656
[root@localhost ~]# cat badprocessID.py #!/usr/bin/env python from multiprocessing import Process import os def output(mypid): print "I am child %d ID :%d\n" % (os.getpid(),mypid) def main(): mypid=os.getpid() p=Process(target=output,args=(mypid,)) print "I am parent %d\n" % os.getpid() p.start() if __name__=="__main__": main()
[root@localhost ~]# cat simplechina.py #!/usr/bin/env python import os from multiprocessing import Process def output(howmany,childpid): info = (howmany,os.getpid(),os.getppid(),childpid) print "i:%d process ID:%d parent ID%d child ID %d\n" % info def chain(howmany): howmany = howmany-1 if howmany > 0: p = Process(target=chain,args=(howmany,)) p.start() output(howmany,p.pid) def main(): childpid = 0 howmany=6 p = Process(target=chain,args=(howmany,)) p.start() if __name__=="__main__": main()
[root@localhost ~]# ./simplechina.py i:5 process ID:13581 parent ID13580 child ID 13582 i:4 process ID:13582 parent ID13581 child ID 13583 i:3 process ID:13583 parent ID13582 child ID 13584 i:2 process ID:13584 parent ID13583 child ID 13585 i:1 process ID:13585 parent ID13584 child ID 13586
[root@localhost ~]# cat simplefan.py #!/usr/bin/env python import os from multiprocessing import Process def output(howmany,childpid): info = (howmany,os.getpid(),os.getppid(),childpid) print "i:%d process ID:%d parent ID%d child ID %d\n" % info def fan(i): output(i,os.getpid()) def main(): pList=[] for i in range(6): p = Process(target=fan,args=(i,)) pList.append(p) for p in pList: p.start() for p in pList: p.join() if __name__=="__main__": main()
[root@localhost ~]# ./simplefan.py i:0 process ID:13594 parent ID13593 child ID 13594 i:2 process ID:13596 parent ID13593 child ID 13596 i:3 process ID:13597 parent ID13593 child ID 13597 i:1 process ID:13595 parent ID13593 child ID 13595 i:4 process ID:13598 parent ID13593 child ID 13598 i:5 process ID:13599 parent ID13593 child ID 13599
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有