Find PID and port number under Windows system


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 3306port to start, but the startup reports a port conflict. At this time, we can find 3306which process the current port corresponds to:

(1) Looking up 3306the PIDnumber corresponding to the port , you can see that the corresponding PIDnumber 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 PIDnumber 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 3306port not to be occupied, you need to end the corresponding process in the task manager, press the shortcut key to Ctrl+Shift+Esccall up the Windows task manager, find it mysqld.exe, and right-click to end the process.
Insert picture description here

2. Find the port number according to PID

Now I want to check PIDthe port number used by the next corresponding process, for example , what port numbers are used by the process searched PIDfor 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
  。。。

Guess you like

Origin blog.csdn.net/wb1046329430/article/details/115211645