In my program, A serve-forever daemon is restarted in a subprocess.
The program itself is a web service, using port 5000 by default.
I don't know the detail of the start script of that daemon, but it seems to inherit the socket listening on port 5000.
So if I were to restart my program, I'll find that the port is already occupied by the daemon process.
Now I am considering to fine tune the subprocess function to close the inherited socket FD, but I don't know how to get the FD in the first place.
It seems like a permission issue. The subprocess is probably running as an other user and therefore you will not have access to the process. Use sudo ps xauw |grep [processname] to figure as under what user the daemon process is running.
How to get a socket FD according to the port occupied in Python?