First, Windows queries the Pid based on the port number:
Command: netstat -ano | findstr "port number"
Example: netstat -ano | findstr 1246 (I use the terminal that comes with idea here)
Then, kill the process based on the Pid:
command : Taskkill -F /pid "PID"
Example: taskkill -F /pid 14860 Find a
way to integrate two commands into one script:
create a new kp.bat file (the script name is taken by yourself)
@echo off
set port=%1%
netstat -ano | findstr %port%
echo please input PID...
set /p pid=%2%
taskkill -F /pid %pid%
The terminal runs the script
Command: kp port number (add a space after the command, then add the port number)
Example: kp 1246
After running here, you can see the pid, and the command enters the state of waiting for input, and then enter the 6264 above, close the process,
and there are some on the Internet that can automatically obtain the return value according to the first command, and add the return value to the first In the two commands, the process can be automatically shut down. I am still studying. There are children's shoes who know how to do it. Welcome to contact (the echo print that is waiting, the Chinese looks garbled)