Kam
Kam

Reputation: 6008

Closing a socket before terminating

When a process writes to a socket the kernel stores this data in an internal buffer first before pushing it though. Now if the process terminates (before closing the socket) with data still in the buffer, the kernel doesn't bother to flush them out.

So my question is:

When a process closes a socket and then dies immediately, are we in a situation where we might loose the data in the buffer? Does the kernel flush the buffer immediately when close socket is called?

Upvotes: 3

Views: 245

Answers (1)

Tony Delroy
Tony Delroy

Reputation: 106068

From the manpage for close:

If fildes refers to a socket, close() shall cause the socket to be destroyed. If the socket is in connection-mode, and the SO_LINGER option is set for the socket with non-zero linger time, and the socket has untransmitted data, then close() shall block for up to the current linger interval until all data is transmitted.

Upvotes: 1

Related Questions