我试图为我的应用服务器使用端口80,但当我执行netstat -aon时,我得到:

TCP 0.0.0.0:80 0.0.0.0:0监听4

当我在任务管理器中查找进程时,它显示PID 4是SYSTEM,就是这样。没有扩展…什么都没有。“系统”。这是怎么回事?

我害怕结束这个过程,我该怎么办?


当前回答

以编程方式标识流程

到目前为止,所有的答案都要求用户进行一些交互操作。这就是当netstat显示PID 4时如何找到PID,而不需要打开一些GUI或处理有关依赖服务的对话。

$Uri = "http://127.0.0.1:8989"    # for example


# Shows processes that have registered URLs with HTTP.sys
$QueueText = netsh http show servicestate view=requestq verbose=yes | Out-String

# Break into text chunks; discard the header
$Queues    = $QueueText -split '(?<=\n)(?=Request queue name)' | Select-Object -Skip 1

# Find the chunk for the request queue listening on your URI
$Queue     = @($Queues) -match [regex]::Escape($Uri -replace '/$')


if ($Queue.Count -eq 1)
{
    # Will be null if could not pick out exactly one PID
    $ProcessId = [string]$Queue -replace '(?s).*Process IDs:\s+' -replace '(?s)\s.*' -as [int]

    if ($ProcessId)
    {
        Write-Verbose "Identified process $ProcessId as the HTTP listener. Killing..."
        Stop-Process -Id $ProcessId -Confirm
    }
}

那可真让我受不了。我讨厌HttpListener,希望我只使用Pode。

其他回答

此外,“开发人员门户”(在Windows 10上)会导致系统在TCP端口上侦听。通常为50080和50443端口。

另一个可能占用端口80的服务是BranchCache

服务。msc将其显示为“BranchCache”

或者使用net命令停止服务

net stop PeerDistSvc

更新:

PeerDistSvc是svhost.exe后面的一个服务,可以查看svchost服务类型

tasklist /svc /fi "imagename eq svchost.exe"

我也有同样的问题。可以通过停止正在运行的服务下的万维网发布服务来修复它。

问题是如何释放它,简单地使用

net stop http

https://stackoverflow.com/a/16243333/777982

对我来说,我必须在我的虚拟机上卸载“Citrix虚拟桌面代理”