端口 8000,PID 4,无法杀死,taskill /f /pid 4,拒绝访问

gar*_*may 2 python windows taskkill simplehttpserver

我无法终止绑定到 8000 端口的进程,因此我无法启动 HTTP 服务器。这是参考问题 Start HTTP/HTTPS server, python -m SimpleHTTPServer

C:\>taskkill /f /pid 4
ERROR: The process with PID 4 could not be terminated.
Reason: Access is denied.
Run Code Online (Sandbox Code Playgroud)

即使在下面杀死也不起作用,我在某处找到了它。

C:\>taskkill /f /s localhost /pid 4
ERROR: The process with PID 4 could not be terminated.
Reason: Access Denied.
Run Code Online (Sandbox Code Playgroud)

PID 4 是系统进程,那里可能正在运行什么,我如何停止它,为什么其他端口是类似的方式侦听。

C:\>netstat -ab

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:135            garg10may-PC:0         LISTENING
  RpcSs
 [svchost.exe]
  TCP    0.0.0.0:443            garg10may-PC:0         LISTENING
 [vmware-hostd.exe]
  TCP    0.0.0.0:445            garg10may-PC:0         LISTENING
 Can not obtain ownership information
  TCP    0.0.0.0:902            garg10may-PC:0         LISTENING
 [vmware-authd.exe]
  TCP    0.0.0.0:912            garg10may-PC:0         LISTENING
 [vmware-authd.exe]
  TCP    0.0.0.0:8000           garg10may-PC:0         LISTENING
 Can not obtain ownership information
Run Code Online (Sandbox Code Playgroud)

Gon*_*tti 5

如果您使用的是 Windows,这可能对您有所帮助,此服务通常使用端口 80:“万维网发布服务”,在控制面板中打开“服务”并停止它


Use*_*ser 2

根据 python文档,http.server还可以使用-m带有端口号参数的解释器开关直接调用该模块。与前面的示例类似,这提供相对于当前目录的文件。

python -m http.server 8000
Run Code Online (Sandbox Code Playgroud)

如果您的端口 8000 已被使用,只需将其更改为另一个端口即可。

python -m http.server 5000
Run Code Online (Sandbox Code Playgroud)

随意杀死进程以及更多的系统进程并不是一个好主意。