In python3 I am creating forked child processes, which I exit - I think - correctly. Here is some code example:
import os
child_pid = os.fork()
if child_pid == 0:
print("I am in the child with PID "+str(os.getpid()))
# doing something
a = 1+1
print("Ending child with PID "+str(os.getpid()))
os._exit(0)
else:
#parent process
os.waitpid(-1, os.WNOHANG)
import time
for x in range(100):
time.sleep(1)
print("waiting...")
Now, as the child process seems to be ended, it still can be seen as a 'defunct' process (while the parent process is still running). How to really get rid of that ended child process? How to change the code?