简体   繁体   中英

Linux on reboot process with PPID 1 do not clean up resources (socket)

Upon system reboot linux my networking application demon with ppid 1 is not tearing down the socket connections. However it tears down the connection if kill that demon using kill -9 manually.

I also notice same behavior if I run a application with nohup. On reboot it is not tearing down connection, where as it tear downs when nohup is not used.

Please provide pointers how to handle proper cleanup resources for demons.

You cannot assume any cleanup whatever in the event that your server process is sent a KILL signal (ie signal 9). It is usual, however, for a service to provide some means to trigger a clean shutdown. That could be in the form of an appropriate handler for the TERM signal (signal 15), which is desirable to have in any case.

Moreover, it is wise to set up your service to be managed via your system's service-management subsystem, whether that's SystemV-style init scripts, systemd, or any of the myriad other alternatives. That way you have a lot more control over how and when the system shuts down your service during a system reboot or shutdown, plus it's easier to manage your service manually when that's needed.

This is an interesting question.

TCP active close requires sending FIN and waiting for FIN/ACK . Obviously, when the system is asked to reboot it should not wait for FIN/ACK . It could still send that FIN or RST though.

However, your other application must not expect the peer to send FIN or RST on connection failure. If you unplug the ethernet cable from the machine, for example, and your application does not send any data, it will never be notified that the peer has disconnected. Instead, your application should send keep-alive messages to detect a broken connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM