pythonwindowssimplehttpservertaskkill

Port 8000, PID 4, not able to kill, taskill /f /pid 4, Access Denied


I am not able to kill process bound to 8000 port, due to which I am not able to start HTTP server. This is in reference to question 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.

Even killing by below is not working which I found somewhere.

C:\>taskkill /f /s localhost /pid 4
ERROR: The process with PID 4 could not be terminated.
Reason: Access Denied.

PID 4 is system process, what might be running on there, how do I stop it, why are other ports is a similar fashion listening.

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

Solution

  • As per python documentation the http.server module can also be invoked directly using the -m switch of the interpreter with a port number argument. Similar to the previous example, this serves the files relative to the current directory.

    python -m http.server 8000
    

    In case your port 8000 is already is being used just change it to another no.

    python -m http.server 5000
    

    It's not a good idea to arbitrarily just kill processes and more over system processes.