对python中的os.getpid()和os.fork()函数详解-创新互联
如下所示:
成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计制作、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的宝坻网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!import os import sys import time processNmae = 'parent' print "Program executing ntpid:%d,processNmae:%s"%(os.gitpid(),processNmae) #attempt to fork child process try: forkPid = os.fork() except OSError: sys.exit("Unable to create new process.") # Am I parent process? if forkPid != 0: print "Parent executingn"+"tpid:%d,forkPid:%d,processNmae:%s"%(os.getpid(), forkPID,processName) # Am I child process? elif forkPID == 0: processName = "child" print "Child executingn" + "tpid: %d, forkPID: %d, processName: %s" % (os.getpid(), forkPID,processName)
print "Process finishingntpid: %d, processName: %s" % (os.getpid(), processName)
网站名称:对python中的os.getpid()和os.fork()函数详解-创新互联
新闻来源:http://scjbc.cn/article/cshpcj.html