我用c#写了一个监听29999端口,进程结束后再次启动发现端口被占用,但是运行netstat -ano | findstr 29999找到进程ID后,却没有这个进程

经查询这个监听29999进程虽然没了,但是要找到他的父进程,把父进程关闭了才可以,参考下面的例子
-
In the first place, you must find the process that is causing the issue using the port number:
netstat -abno | findstr /i "listening"| find ":3000" TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 3116 -
secondly, you must find the parent process id (ppid) using code from @Michael
wmic process get processid,parentprocessid | findstr/i 3116 3116 23828 -
Next, you must find the child process ids using the next code
wmic process where (ParentProcessId=23828) get Caption,ProcessId,CommandLine Caption ProcessId wireguard.exe 27400

文章讲述了作者在使用C#编写监听29999端口的应用时遇到的问题,进程结束后端口仍被占用。通过netstat和WMIC命令追踪到相关的父进程和子进程,最终发现是conhost.exe进程导致的。解决方法是找到并结束所有相关子进程,避免重启系统。
1726

被折叠的 条评论
为什么被折叠?



