Python forked processes won't die
<p>I've seen several questions like this one, but after trying various variants of checking if the children are alive and exiting the children processes, I simplified the problem and still it will not work.</p>

<p>Am I wrong in exiting a forked process with sys.exit(0)?
Is there another way to kill it. The thing is, I cannot have the parent kill the processes since it won't know when they're done working.</p>

<p>At first I thought it was because a executed a system command before exiting (http://stackoverflow.com/questions/6807102/python-run-system-command-and-then-exit-wont-exit), but I've even removed that in the simplified version as given solution didn't work either.</p>

<p>Here's an example:</p>

<pre><code>import sys
import os
import time

children = []

for i in range(0,3):    
    pid = os.fork()

    if pid == -1:
        continue
    elif pid == 0:
        # Do work...
        print 'Child %d spawned' % os.getpid()
        sys.exit(0)     
    else:
        children.append(pid)

time.sleep(5)
for pid in children:
    proc_path = '/proc/%d' % pid
    if not os.path.exists(proc_path):
        print 'Child %d is dead' % pid
    else:
        print 'Child %d is alive' % pid
</code></pre>

<p>This prints:</p>

<pre><code>Child 27636 spawned
Child 27637 spawned
Child 27638 spawned
Child 27636 is alive
Child 27637 is alive
Child 27638 is alive
</code></pre>

<p>But child processes should be dead.</p>

<p>What causes these processes to become zombies in this case?</p>
