【问题标题】:How can I identify which process is using port 18780 on Windows?如何识别 Windows 上哪个进程正在使用端口 18780?
【发布时间】:2020-08-04 10:59:27
【问题描述】:

我有一个内部 Web 应用程序正在侦听端口 18780 上的所有 IP。当我尝试在新的 Windows VM 上启动该应用程序时,它会引发以下异常:

System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:18780

重新启动机器后,应用程序启动正常,但我希望避免在使用之前重新启动所有新的 QA 环境。

IANA reports that nothing well-known uses port 18780.

上次发生这种情况时,我试图确定该端口上正在运行的进程:

运行Get-Process -Id (Get-NetTCPConnection -LocalPort 18780).OwningProcess 返回Cannot find a process with the process identifier 7188。 Powershell 正在本地管理员帐户下运行。

那么这里发生了什么?看起来有东西在使用该端口,它有一个进程 ID,但我无法获得它的详细信息。第二次运行这个 powershell 命令报告说没有任何东西在监听那个端口。观察行为会改变 Windows 进程吗?

我可以采取哪些进一步的步骤来了解有关薛定谔过程的更多信息?

【问题讨论】:

    标签: windows port


    【解决方案1】:

    在 powershell 中尝试以下操作:

    netstat -ano | findstr :<port> 
    

    这将为您提供有关进程 ID 的详细信息

    然后使用以下命令终止进程:

    taskkill /PID <processid> /F
    

    【讨论】:

      【解决方案2】:

      又发现了这种情况。

      原来我的应用程序产生了三个子进程,而且这些子进程仍在运行。在拥有进程 record 被清理之前,Windows 显然不会释放 TCP 端口,并且子进程会维护此记录。即使父进程停止,并在 TCPViewer 中显示为&lt;non-existent&gt;,端口仍然不可用。

      这里也有描述:https://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process

      我使用wmic process where (ParentProcessId=7188) get Caption,ProcessId 来确定要杀死哪些子进程,这就成功了。 Windows 立即发布了该端口。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多