I have a server that listens for socket connections and performs different actions depending on the request. One of them is long-term database queries for which there are server forks.
The server keeps a log of all active children and whenever it is asked to turn it off, it will kill all its children before exiting. A couple of times I came across a situation where the server crashed or was killed ruthlessly, which led to the fact that the child process became an orphan. If I try to return the server back, it will refuse to say that the listening socket cannot communicate, because this address / port is already connected.
I am looking for a way to improve this situation, so that the main server process can return immediately. I tried to control the parent creature from the child and leave as soon as it disappeared, but this only led to the fact that it had zombie processes, and the socket seems to be still connected.
The server is written in Python, but any explanation or suggestion in any language is welcome.
source
share