Article Directory
1. Find the PID according to the port number
This kind of situation is often encountered in work, that is, when a software is installed in the Windows system, the startup failure is likely to be caused by the port number being occupied. At this time, we need to find out whether the port number is occupied.
For example, one of our programs needs a 3306
port to start, but the startup reports a port conflict. At this time, we can find 3306
which process the current port corresponds to:
(1) Looking up 3306
the PID
number corresponding to the port , you can see that the corresponding PID
number is 5320
:
C:\Users\张三>netstat -ano|findstr 3306
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 5320
TCP 0.0.0.0:33060 0.0.0.0:0 LISTENING 5320
TCP [::]:3306 [::]:0 LISTENING 5320
TCP [::]:33060 [::]:0 LISTENING 5320
(2) Find the process corresponding to the PID
number again 5320
, you can see that the corresponding process is mysqld.exe
:
C:\Users\张三>tasklist|findstr 5320
mysqld.exe 5320 Services 0 4,728 K
If you want the 3306
port not to be occupied, you need to end the corresponding process in the task manager, press the shortcut key to Ctrl+Shift+Esc
call up the Windows task manager, find it mysqld.exe
, and right-click to end the process.
2. Find the port number according to PID
Now I want to check PID
the port number used by the next corresponding process, for example , what port numbers are used by the process searched PID
for 5320
:
C:\Users\张三>netstat -ano|find "5320"
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 5320
TCP 0.0.0.0:33060 0.0.0.0:0 LISTENING 5320
TCP 127.0.0.1:49697 127.0.0.1:49698 ESTABLISHED 5320
TCP 127.0.0.1:49698 127.0.0.1:49697 ESTABLISHED 5320
TCP [::]:3306 [::]:0 LISTENING 5320
TCP [::]:33060 [::]:0 LISTENING 5320
3. View all open ports
Check which ports are open on this machine:
C:\Users\张三>netstat -anp tcp
活动连接
协议 本地地址 外部地址 状态
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP 0.0.0.0:4369 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5040 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5672 0.0.0.0:0 LISTENING
TCP 0.0.0.0:8680 0.0.0.0:0 LISTENING
TCP 0.0.0.0:19531 0.0.0.0:0 LISTENING
TCP 0.0.0.0:25672 0.0.0.0:0 LISTENING
TCP 0.0.0.0:25819 0.0.0.0:0 LISTENING
。。。