1

I have problem same as in this question.

PID exists in netstat but does not exist in task manager

I have discovered a running process with PID 26376 listening on port 9001 and 9002 as when I try to run my program(as a service) which binds to that port it fails.

But when I try to kill it using taskkill /PID it says that the process 26376 is not found. Similarly when I try to find the process in task manager with "Show processes from all users" selected, I couldn't find it anywhere.

And the accepted answer says:

What may be happening is that your process had a TCP port open when it crashed or otherwise exited without explicitly closing it. Normally the OS cleans up these sorts of things, but only when the process record goes away.

I am working on a C++ code and to fix an unknown/unresolved issue I am doing taskkill which sometimes locks the port. How do I free it on next use without restarting the whole OS? Is there any way to free such ports?

Community
  • 1
  • 1
SMUsamaShah
  • 6,991
  • 21
  • 84
  • 121

1 Answers1

-1

The TCP TIME-WAIT state will remain for 2MSL , so that the port will still be held open. You can set socketopt SO_REUSEADDR, it will work.

See this.

Community
  • 1
  • 1