小弟刚学python,有个问题想请教,父进程与子进程的问题,求大神解答,代码在下面给出:
源代码:
import os
from time import sleep
pid = os.fork()
if pid <0 :
print("create process failed")
elif pid == 0:
sleep(3)
print("this is child process")
else :
sleep(1)
print("this is parent process")
print("******the end*******")
结果:
this is parent process
******the end*******
Process finished with exit code 0
无论我跑多少次,一直都没有子进程的结果,而我把时间对调之后,就会既显示父进程也显示子进程了,为什么子进程sleep时间比父进程长,就不会显示子进程了呢?另外我Debug了一下,结果又不一样了。
debug结果:
Connected to pydev debugger (build 191.7479.30)
this is child process
******the end*******
程序未结束,可是不显示父进程的东西了,到底为什么,搞不懂了,大神解释下啊!谢谢各位了!!!