简体   繁体   English

具有PPID 1的Linux on重新启动过程不会清理资源(套接字)

[英]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. 在系统重新启动linux之后,我的ppid 1网络应用程序恶魔没有断开套接字连接。 However it tears down the connection if kill that demon using kill -9 manually. 但是,如果使用kill -9手动杀死那个恶魔,它将断开连接。

I also notice same behavior if I run a application with nohup. 如果我使用nohup运行应用程序,我也会注意到相同的行为。 On reboot it is not tearing down connection, where as it tear downs when nohup is not used. 在重新启动时,它不会断开连接,而在不使用nohup的情况下,连接也会断开。

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). 如果向服务器进程发送KILL信号(即信号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. 在任何情况下都希望具有适用于TERM信号(信号15)的适当处理程序的形式。

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. 此外,明智的做法是将服务设置为通过系统的服务管理子系统进行管理,无论是SystemV样式的初始化脚本,systemd还是其他众多替代方法。 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 . TCP活动关闭要求发送FIN并等待FIN/ACK Obviously, when the system is asked to reboot it should not wait for FIN/ACK . 显然,当要求系统重新启动时,它不应等待FIN/ACK It could still send that FIN or RST though. 它仍然可以发送FINRST

However, your other application must not expect the peer to send FIN or RST on connection failure. 但是,您的其他应用程序一定不能期望对等方在连接失败时发送FINRST 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. 相反,您的应用程序应发送保持活动消息以检测断开的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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