Forking python, defunct child

后端 未结 2 1537
后悔当初
后悔当初 2021-02-03 14:55

I have some troubles with Python child processes so I wrote a very simple script:

import os
import sys
import time

pid = os.fork()
if pid:
    #parent
    time.         


        
2条回答
  •  终归单人心
    2021-02-03 15:39

    To clear the child process in Unix you need to wait on the child, check one of the os.wait(), os.waitpid(), os.wait3() or os.wait4() at http://docs.python.org/2/library/os.html#os.wait

    As to why this is so, this is a design decision of Unix. The child process keeps its return value in its process state, if it was to disappear you'll have no return value. The os.wait() also returns to you the return value and then the child process is released and all associated resources are released.

提交回复
热议问题