Hi I have a big interest in how kernel handles this situaction. Lets assume that we have two hosts: host 1 and host 2 and on host 1 I have started this command: nc -l -p 4444 on host 2 I have started this command (2 means IP addres of second host here!): nc 2 4444 Now i can send msgs betweem them. In time I have decided to end connection. To do this I'm using ctrl+c on host 2. What functions are called to clean broken socket on host 1? What functions are called to clean up socket on host 2? Grzegorz.
On Thu, Nov 6, 2014 at 2:07 PM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:
To do this I'm using ctrl+c on host 2. What functions are called to clean broken socket on host 1? What functions are called to clean up socket on host 2?
Have you tried running strace on the nc processes?
Am 2014-11-06 22:30, schrieb Jim Davis:
On Thu, Nov 6, 2014 at 2:07 PM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:
To do this I'm using ctrl+c on host 2. What functions are called to clean broken socket on host 1? What functions are called to clean up socket on host 2?
Have you tried running strace on the nc processes?
Additionally you can use the Kernel's ftrace[0] functionality to figure out which functions are being called in the kernel (instead of getting only the system calls returned like with strace). [0] https://www.kernel.org/doc/Documentation/trace/ftrace.txt
When a socket is closed at one side of the communication, the other side will not get to know this information. In your case, when ctrl+c is performed, socket is terminated abruptly at host1 end. Until, host2 tries to read from this broken connection, host 2 will not know that the connection is broken and it will keep the same conn alive. The moment, host2 tries to read from this socket, it will come to know that the connection is broken and it will terminate the connection. The logical flow of function(system calls) at host2 would be read() -> Application would receive an error on read call shutdown() ->depends on the application you are using close() Then depending on the application, if it decides to terminate, it will call exit() as well. you can see the man pages of these commands for more information. On Fri, Nov 7, 2014 at 2:37 AM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:
Hi
I have a big interest in how kernel handles this situaction.
Lets assume that we have two hosts: host 1 and host 2 and on host 1 I have started this command: nc -l -p 4444 on host 2 I have started this command (2 means IP addres of second host here!): nc 2 4444
Now i can send msgs betweem them. In time I have decided to end connection. To do this I'm using ctrl+c on host 2. What functions are called to clean broken socket on host 1? What functions are called to clean up socket on host 2?
Grzegorz.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Sreejith -------------------------------------------------------------------------------------------------------- Aint no grave, can hold my body down!!! "Obadiah 1:4"
Hi On Fri, Nov 7, 2014 at 2:37 AM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:
Hi
I have a big interest in how kernel handles this situaction.
Lets assume that we have two hosts: host 1 and host 2 and on host 1 I have started this command: nc -l -p 4444 on host 2 I have started this command (2 means IP addres of second host here!): nc 2 4444
Now i can send msgs betweem them. In time I have decided to end connection. To do this I'm using ctrl+c on host 2. What functions are called to clean broken socket on host 1? What functions are called to clean up socket on host 2?
I'm not expert on this but from what your steps suggests at the kernel level both machines know there's no communication between them. When you hit ctl+c or send your process signal which is not handled then by default that process is killed. When you open a socket, it's actually linked to a file via sockfs, this is socket is on your opened file lists so assuming you didn't forked and the refcount was still 1 for this sockfs inode the do_exit would perform cleanup when it calls fput on these opened files. That would terminate the socket by calling sock_release, see net/socket.c. So the application at the other end doesn't yet know about it but it'll when it attempts to go and read since the kernel at the other end already knows that this connection has been terminated. For specific functions you'll need to see net/ipv4[6]/. something like sock_close/ sock_disconnect? What would be interesting if you took the ether cable out or just turned off power? It won't be a clean shutdown then :-p.
Grzegorz.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- ---P.K.S
participants (5)
-
Grzegorz Dwornicki -
Jim Davis -
Pranay Srivastava -
Silvan Jegen -
Sreejith M M