开发中偶尔会出现端口被占用的情况,简单介绍下排查方式:
1、windows下使用命令 netstat -ano,会出现如下内容:
可以获取到协议类型(TCP、UDP),本地地址与端口号,访问的外部地址与端口号,连接的建立状态,以及PID(进程号)。
也可以针对某一个端口号进行精确查找,命令如下:netstat -aon|findstr "8080"。
2、根据占用的端口号查PID,比如以8080端口为例:
可以看到8080端口上正在跑着PID为7020的进程。
3、根据PID确定进程:
打开任务管理器-进程选项卡,可以看到:
这样就找到PID为7020的进程是哪一个,再进行相应的后续处理即可。