I have a chain of three processes: Process A calls B to spawn C, then B dies. We can call B a "bridge" between two systems A and C.
I want to make sure that C DOES NOT inherit any file descriptors that A opens in order to prevent zombying, which I am currently observing (sometimes A calls B to kill C, and after this, I am seeing defunct C processes hanging around, but I don't know what the code in A looks like).
To make sure this issue isn't due to stdin/out/err being passed down, I am currently doing the following in B
def _close_fds(): #workaround carstens bug
for fd in [0, 1, 2]:
try:
os.close(fd)
except Exception:
logger.info("File descriptor was not open")
...
_close_fds() #make sure there are no open file descriptors for the chile to enherit
pid = subprocess.Popen([_ROOT_PATH + "something.py"]).pid
...
Is there a better way to do this?