如题

查看所有的端口占用情况

1
2
3
4
5
6
7
C:\>netstat -ano
Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 15372
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 1140
# 还有好多,这里省略...

查看指定端口的占用情况

这里以 80 端口为例

1
2
C:\>netstat -aon|findstr 80
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 11880

查看 PID 对应的进程

1
2
3
4
5
6
7
# 从上面运行 netstate 命令查询到 80 端口的进程 ID 为 11880,以下查看该进程 ID 对应的程序
C:\>tasklist|findstr 11880
nginx.exe 11880 Console 1 6,548 K

# 以下查询进程 ID 2940 是哪个程序在运行
C:\>tasklist|findstr 2940
java.exe 2940 Console 1 674,380 K

杀死进程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# nginx 占用了 80 端口,结束该进程:
C:\>taskkill /f /t /im nginx.exe
SUCCESS: The process with PID 11880 (child process of PID 14416) has been terminated.
SUCCESS: The process with PID 14416 (child process of PID 4896) has been terminated.

# 杀死 java.exe 进程
C:\>taskkill /f /t /im java.exe
SUCCESS: The process with PID 3772 (child process of PID 37764) has been terminated.
SUCCESS: The process with PID 41376 (child process of PID 18720) has been terminated.
SUCCESS: The process with PID 33892 (child process of PID 29432) has been terminated.
SUCCESS: The process with PID 28732 (child process of PID 20972) has been terminated.
SUCCESS: The process with PID 37764 (child process of PID 34648) has been terminated.
SUCCESS: The process with PID 18720 (child process of PID 34648) has been terminated.
SUCCESS: The process with PID 29432 (child process of PID 34648) has been terminated.
SUCCESS: The process with PID 20972 (child process of PID 34648) has been terminated.

应用

  1. Idea 启动时报错
  2. 解决
    1
    2
    3
    4
    5
    C:\Users\Andy>netstat -aon|findstr 4440
    TCP 192.168.1.188:4440 220.181.76.83:80 ESTABLISHED 7352

    C:\Users\Andy>tasklist|findstr 7352
    YoudaoDict.exe 7352 Console 1 26,096 K

手动关闭有道词典,或者运行:taskkill /f /t /im YoudaoDict.exe

1
2
3
4
5
C:\>taskkill /f /t /im YoudaoDict.exe
SUCCESS: The process with PID 7352 (child process of PID 23172) has been terminated.
SUCCESS: The process with PID 19064 (child process of PID 23172) has been terminated.
SUCCESS: The process with PID 17396 (child process of PID 23172) has been terminated.
SUCCESS: The process with PID 23172 (child process of PID 8848) has been terminated.