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

查看:28
本文介绍了pid 0 拥有的 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 上创建大量到本地主机的 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.

我不熟悉服务点管理器,但它没有理由跟踪处于 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 0 拥有的 TCP 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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