概述
有同事最近遇到了一个问题,在运行某个程序的时候,总提示说程序端口被占用,不能运行,那么,在winserver下怎么知道端口是被哪个程序占用了呢?下面我们一起来看看具体内容。

1、Windows查看所有的端口
点击电脑左下角的开始,然后选择运行选项,接着我们在弹出的窗口中,输入【cmd】命令,进行命令提示符。
然后在窗口中输入【netstat -ano】按下回车,即会显示所有的端口占用情况。如图所示:

2、查询指定的端口占用
在窗口中,继续输入【netstat -aon|findstr "提示的端口"】,例如提示的端口为8080,那么就输入命令为【netstat -aon|findstr "8080"】,回车之后就可以看见列表中的PID,然后根据PID在电脑的任务管理器中查看对应的占用程序,接着进行关闭即可。

3、查询PID对应的进程
如果在上面步骤之后,我们得到的PID为9564,那么就可以输入命令【tasklist|findstr "9564"】,在第一行显示的名字就是程序名,以下可以看到很明显是微信占用的端口。

4、杀掉进程
输入命令【taskkill /f /t /im 程序名】即可

后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~
如果你觉得这篇文章对你有帮助, 请小小打赏下.
