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.
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