pid零拥有的TCP连接 [英] TCP connection owned by pid zero

查看:192
本文介绍了pid零拥有的TCP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确保Windows服务程序(运行在.NET之上)正确释放其网络连接。

I'm trying to ensure that a Windows service program (running on top of .NET) is properly releasing its network connections.

在本地运行服务时,知道它将在端口57300上创建许多到localhost的HTTP连接。我正在使用 netstat 监视它们是否被正确释放。

When running the service locally I know that it will create a lot of HTTP connections to localhost on port 57300. I'm using netstat to monitor whether they are released properly.

我很惊讶地看到,与该端口的许多连接都归系统空闲进程所有(PID = 0)。

I was suprised to see that many connections to this port are owned by the "System Idle process" (PID=0).

在这里我们可以看到其中只有三个连接归服务程序所有(PID = 5012)。其他所有其他对象归PID 0所有。

Here we can see that only three of those connections are owned by the service program (PID=5012). All the others are owned by PID 0.

我的主要问题是:为什么会这样?我需要注意?

但我也想知道:


  • 这是否意味着服务程序确实释放了连接?

  • Does this mean that the service program did release the connection properly, or not?

如果需要,可以重新使用这些连接吗?

Will such connections be reused if needed?

在.NET ServicePointManager

推荐答案

TCP连接关闭后,它将进入TIME_WAIT状态一段固定的时间。这是为了确保与连接有关的所有仍在网络中排队的数据包都不会干扰新连接。

After a TCP connection closes, it goes into the TIME_WAIT state for a fixed period. This is to ensure that any packets related to the connection that might still be queued up in the network won't interfere with new connections.

由于即使原始进程已经退出,这也必须发生,我猜测Windows会自动将所有权转移给系统进程。

Since this has to happen even if the original process has exited, I'm guessing that Windows automatically transfers ownership to the system process.

所以,我相信您对最后四个问题的回答是:

So, I believe the answers to your last four questions are:


  • 不,您可能不必为此担心。

  • No, you probably don't need to worry about this.

是的,服务程序已正确释放了连接。

Yes, the service program released the connection properly.

如果系统用尽,TIME_WAIT连接将提前 TCB 。在默认配置中,这将在端口用完之前发生,因此,实际上,是的,如果需要它们,连接将被重用。

The TIME_WAIT connections will be closed early if the system runs out of TCBs. In the default configuration this will happen before you run out of ports, so in effect, yes, the connections will be reused if they are needed.

I'我不熟悉服务点管理器,但是没有理由让它跟踪TIME_WAIT状态的连接,所以可能没有。

I'm not familiar with the service point manager, but there's no reason for it to track connections in the TIME_WAIT state, so probably no.

在Windows XP上,TIME_WAIT延迟的默认值是两分钟。我找不到更多的最新信息,但是自那以后似乎没有改变过。

On Windows XP, the default value for the TIME_WAIT delay was two minutes. I can't find more recent information, but it seems likely that it hasn't been changed since then.

这篇关于pid零拥有的TCP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆