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.....‘)
时间: 2024-10-23 12:50:24