I've read up this question about Linux, Can a port be bound when the process has terminated?
Linux appears to clean up after processes exiting, and leaving open sockets. I was wondering if there's any specification about how this works on Windows.
Does the OS consistently take care of closing sockets for processes which exit without closing them?
|
| ||||
|
feedback
|
|
On both Windows and Unixen, when a process exits the kernel closes all open handles. Windows NT
Linux
Note that on both operating systems,
| |||||||||
feedback
|
|
On Windows, a socket is a link between a communications endpoint and a process. This is why, when you duplicate a socket, you wind up with two sockets but only one endpoint. This is why you can't pass a socket from one process to another without creating a new socket in the other process. If the process ceases to exist, its sockets necessarily cease to exist. There is no concept of a socket without a process to hold it. This is why even Windows kernel drivers that wish to create sockets at kernel level must specify a process to own the socket or call the function from a process context that can own the socket. (Or they can manipulate the endpoints directly without using sockets.) Your question seems to really be not about sockets but about the communication endpoints themselves. A socket has a reference to its communication endpoint. When the socket goes away, the reference count drops. If it hits zero, it will be removed as soon as that is permissible given the requirements of the communication protocol that endpoint is associated with. TCP has a TIME_WAIT state during which the endpoint must be kept around to handle any "leftover" packets. | |||
|
feedback
|
|
Yes it does. It has been this way sense windows | |||||||||||||||||
feedback
|