代码:
import mmap import osmm = mmap.mmap(-1, 13) mm.write(b"pid:") mm.write(str(os.getpid()).encode('utf-8'))pid = os.fork()if pid == 0: #子进程,这个fork和php的很像mm.seek(0)print(mm.readline().decode('utf-8'))print('id:%s' % os.getpid())mm.close()
输出:
pid:73093 id:73094