linux-多进程

"""
linux下使用os.fork() 方法
结合getpid()  getppid()方法
编码验证父子进程"""
# import os
# print('main-----------------')
# pid = os.fork()
# # after using the method whose name is fork , every line after the line where do fork all will be done
# print('===========================')
# print('*****************************************')
# print(os.getpid(), os.getppid())

"---------------------------------------------------------------------------------------------------------"
# import os
# print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`')
# # zhujinchengdayin
# os.fork()
# # zhujincheng zhujinchengfuzhijincheng=c1 dayin 2
# print('-----------------------------------')
# # zhujincheng cp c2 c1 cp c3|  zhujincheng c1 c2 c3 dayin 4
# os.fork()
# # zhujincheng c1 c2 c3 dayin 4
# print('....................................................')
# # zhujincheng cp c4 c1 cp c5 c2 cp c6 c3 cp c7
# os.fork()
# # zhujincheng c1 c2 c3 c4 c5 c6 c7 dayin 8
# print('+++++++++++++++++++++++++++++++++++')

"---------------------------------------------------------------------------------------------------------"
import os
pid = os.fork()
if pid == '0':
    print('child.pid..', pid)
    print('child.getpid..', os.getpid())
    print('partent...', os.getppid())
else:
    print('pid..', pid)
    print('getpid..', os.getpid())
    print('partent...', os.getppid())


fork 返回进程号,子进程返回0,父进程返回子进程进程号

fork下代码当前进程及其子进程都会执行

猜你喜欢

转载自blog.csdn.net/baidu_40450846/article/details/89108464