When troubleshooting problems on the linux server side, we sometimes encounter that a port is occupied by multiple applications, or when developing miscellaneous windows, we find that the port required by the system is occupied by other programs when starting the application. How to know who has it? The port we need is a headache for many people. Here is a very simple method, I hope it will be useful to everyone:
In Windows environment:
Start--run--cmd Enter the command prompt and enter netstat -ano to see the PID of all connections. After that, find the program corresponding to this PID in the task manager. If there is no PID in the task manager, you can find it in the task manager In the manager, select "View" - "Select Columns"
Active Connections
Protocol Local Address External Address Status PID
TCP 0.0.0.0:7 0.0.0.0:0 LISTENING 3012
TCP 0.0.0.0:9 0.0.0.0:0 LISTENING 3012
TCP 0.0.0.0: 13 0.0.0.0:0 LISTENING 3012
TCP 0.0.0.0:17 0.0.0.0:0 LISTENING 3012
TCP 0.0.0.0:19 0.0.0.0:0 LISTENING 3012
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 332
TCP 0.0. 0.0:443 0.0.0.0:0 LISTENING 3348
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:902 0.0.0.0:0 LISTENING 3112
TCP 0.0.0.0:912 0.0.0.0:0 LISTENING 3112
TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 2964
If we need to determine who is occupying our port 2964, enter the following command at the command line:
C:\Users\Administrator> netstat -ano|findstr "2964"
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 2964
It is found that the port is occupied by the application whose process PID is 2964
What is the application whose process PID is 2964? Enter the following commands at the command line:
C:\Users\Administrator> tasklist|findstr 2964
mysqld.exe 2964 Services 0 10,828 K
To end the application process, enter the following command:
Under linux environment:
1. Find the occupied port
netstat -tln
netstat -tln | grep 8080
netstat -tln checks the port usage, while netstat -tln | grep 8080 only checks the usage of port 8080
2. Check which program the port belongs to? Which process is occupied by the port
lsof -i:8060
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Java 20804 root 36u IPv6 35452317 0t0 TCP *:pcsync-https (LISTEN)
3. Kill the process occupying the port and kill it according to the pid
kill -9 process id
kill -9 20804