Windows/Linux下如何查看某个端口被谁占用

在Windows/Linux下开发时经常遇到端口重复而报异常的情况:比如

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 10000 was already in use.

Action:

Identify and stop the process that's listening on port 10000 or configure this application to listen on another port.

下面介绍如何查看某个端口被谁占用,如何杀死该端口进程。

Windows

1、打开命令窗口(以管理员身份运行)

window+R 组合键,调出命令窗口。

2、查看被占用端口对应的 PID

输入命令:

netstat -aon|findstr "10000"

回车执行该命令,最后一位数字就是 PID, 这里是 7992

3、查看指定 PID 的进程

继续输入命令:

tasklist|findstr "7992"

回车执行该命令。

 是程序:yundetectservice.exe 占用了端口

4、结束进程

强制(/F参数)杀死 pid 为 7992 的所有进程包括子进程(/T参数):

taskkill /T /F /PID 7992

Linux

1、查看端口号占用情况,如:6010

netstat -anp |grep 6010

2、结束占用端口的进程

kill -9 2503

3、查看所有端口情况 确认已结束进程

netstat -ntlp

猜你喜欢

转载自blog.csdn.net/zzj_csdn/article/details/127602363