首页 > 代码库 > python 进程

python 进程

import os
import time
ret = os.fork() # 创建子线程

if ret ==0: # 子进程中返回值为0,父进程>0
    while True:
        print(......1......)
        time.sleep(1)

else:
    while True:
        print(......2......)
        time.sleep(1)

技术分享

 多fork问题,以下代码会出现4个进程

import os
import time
ret = os.fork()

if ret ==0:
    print(......1......)

else:
    print(......2......)


ret = os.fork()

if ret ==0:
    print(......11......)

else:
    print(......22.....)

技术分享

技术分享

import os
import time
ret = os.fork()

if ret ==0:
    print(......1......)

else:
    print(......2......)


    ret = os.fork()

    if ret ==0:
        print(......11......)

    else:
        print(......22.....)

技术分享

技术分享

 

python 进程