我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。
我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。
我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。
我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。
当前回答
这在mac中很管用
sudo kill -9 $(netstat -vnap tcp | grep PORT | awk -F " " '{print $9}')
其他回答
Git Bash的其他方式:
stopProcessByPortNumber() {
port=":${1}"
portStrLine="$(netstat -ano | findstr LISTENING | findstr $port)"
processId="$(grep -oP '(\d+)(?!.*\d)' <<< $portStrLine)"
echo $processId
taskkill -PID $processId -F
}
这是Windows的解决方案:
C:\Users\Niroshan>netstat -ano|findstr "PID :8080"
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 18264
taskkill /pid 18264 /f
这在mac中很管用
sudo kill -9 $(netstat -vnap tcp | grep PORT | awk -F " " '{print $9}')
Lsof -i tcp:8000 该命令列出8000端口上运行的进程信息 kill -9 [PID] 该命令终止进程
选项1在特定端口上只杀死LISTEN的一行程序:
kill -9 $(lsof -t -i:3000 -sTCP:LISTEN)
选项2如果你安装了npm,你也可以运行
npx kill-port 3000