windows
手动录入端口
新建一个bat文件,内容如下:
@ECHO OFF
set /p portid=Enter the Port to be killed:
echo %portid%
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr %portid% ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine
:SkipLine
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%
PAUSE
双击运行后,输入端口号即可杀掉对应的进程。
固定端口
set portid=12306
echo %portid%
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr %portid% ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine
:SkipLine
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%
根据标题结束进程
并行启动多个进程:
start "<window title>" <command will be executed>
例子:
start "service1" mvn clean spring-boot:run
start "service2" mvn clean spring-boot:run
获取进程的PID(可选):
tasklist /V /FI "WindowTitle eq service1*"
tasklist /V /FI "WindowTitle eq service2*"
杀死进程:
taskkill /FI "WindowTitle eq service1*" /T /F
taskkill /FI "WindowTitle eq service2*" /T /F
linux
linux查端口进程占用情况。这里以端口为8086
为例。
lsof -i:8086
直接杀掉进程
kill $(lsof -t -i:8086)