admin 管理员组文章数量: 1086019
For a test setup, I have two separate applications (buildt with gcc), in this instance running on the same physical machine. One opens a TCP socket, accepting incoming connections, and sends data on a regular interval. After establishing connection, the transmission happen in a while (1) loop. The second one is a GTK application, receiving and plotting the transferred data. For testing I run both on the same machine, started from separate terminals.
When I close the GTK application, either via the display window's close button or Ctrl-C in the terminal, the sender application in the other terminal terminates also. But how come ? Is this behavior specified ?
What I almost fot - host operating system is Linux. Specifically, Mint 20.3, an Ubuntu-based distro.
For a test setup, I have two separate applications (buildt with gcc), in this instance running on the same physical machine. One opens a TCP socket, accepting incoming connections, and sends data on a regular interval. After establishing connection, the transmission happen in a while (1) loop. The second one is a GTK application, receiving and plotting the transferred data. For testing I run both on the same machine, started from separate terminals.
When I close the GTK application, either via the display window's close button or Ctrl-C in the terminal, the sender application in the other terminal terminates also. But how come ? Is this behavior specified ?
What I almost fot - host operating system is Linux. Specifically, Mint 20.3, an Ubuntu-based distro.
Share Improve this question edited Mar 27 at 13:20 codis asked Mar 27 at 12:55 codiscodis 11 bronze badge 5 |1 Answer
Reset to default 0.... --- SIGPIPE (Broken pipe) --- +++ killed by SIGPIPE +++
Your comment basically is the answer: The call to send fails since the TCP connection has been closed - which is handled automatically by the OS kernel if the process owning the TCP connection exits. Since the TCP connection is closed by the peer an attempt to send more data (or the close with still unread data) cause a TCP RST, i.e. "Connection reset". This will cause a SIGPIPE, unless the application has specifically handled this case, like using MSG_NOSIGNAL flag for send. And since SIGPIPE is not catched by your application the application will be killed by the OS.
本文标签: connectionhow does closing a TCP socket cause the remote application to terminateStack Overflow
版权声明:本文标题:connection - how does closing a TCP socket cause the remote application to terminate? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744087833a2531467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
echo $?
in Bash)? When it exits, does it execute any code (e.g. a printf) which is after the loop? – grawity_u1686 Commented Mar 27 at 14:39