最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Windows中查看哪个进程占用某端口号并杀掉该进程

Windows crifan 431浏览 0评论
折腾:
【未解决】windows中PyInstaller打包exe运行报错:Failed to execute script pyi_rth_pkgres ModuleNotFoundError pkg_resources.py2_warn
期间,所以希望从端口号4242入手,找到哪个程序正在用此端口
所以问题转换为:
windows中命令行中如何查看进程的端口号
windows check task  port
networking – How can you find out which process is listening on a port on Windows? – Stack Overflow
结果:
【部分解决】windows中执行netstat命令提示:请求的操作需要提升
C:\Windows\system32>netstat -a -b | findstr /i 4242
  TCP    127.0.0.1:4242         account:0              LISTENING
但是此处属于阻塞的,不返回的:
所以还要搞清楚如何是不阻塞的,直接返回的
windows – how to use netstat -nb in python – Stack Overflow
试试:
netstat -nb
是立刻返回的:
C:\Windows\system32>netstat -nb | findstr /i 4242


C:\Windows\system32>netstat -nb | findstr /i zmq
也没找到
还是去搞清楚:
【已解决】windows中netstat命令的语法和常见用法和含义
但是属于哪个进程,进程名称
C:\Windows\system32>tasklist | findstr 20584
python.exe                   20584 Console                    2     10,168 K
Use Netstat to See Listening Ports and PID in Windows
另外也去看看 任务管理器
果然可以找到这个进程。
去看看位置:
右键-》打开文件所在的位置
找到了此处的Python虚拟环境virtualenv中env中的python
然后参考:
cmd – How to kill the process currently using a port on localhost in windows? – Stack Overflow
windows – Command line for looking at specific port – Stack Overflow
去用
taskkill /F /pid <process ID>
可以杀掉进程
【总结】
此处去查找4242端口被哪个进程占用:
netstat -ano | findstr port_number
可以看到pid进程编号,然后去杀掉进程:
taskkill /f /pid pi_number
举例:
>netstat -ano | findstr 4242
  TCP    127.0.0.1:4242         0.0.0.0:0              LISTENING       20584


成功: 已终止 PID 为 20584 的进程。

转载请注明:在路上 » 【已解决】Windows中查看哪个进程占用某端口号并杀掉该进程

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.188 seconds, using 23.29MB memory