我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。

我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。


当前回答

kill -9 ' fuser 8080/tcp|xargs -n 1 ',该命令同时关闭监听8080端口的tcp连接进程

其他回答

这是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

这将杀死端口80上运行的程序

sudo fuser -k 80/tcp

可以使用lsof命令。 假设端口号是8090

lsof -i:8090

该命令返回该端口上的开放进程列表。

之类的……

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 75782 eoin 5u IPv6 0x01c1c234 0t0 TCP localhost:8090 (LISTEN)

要释放端口,杀死使用它的进程(进程id是75782)…

kill -9 75782

这个方法对我很管用。 这是原文的链接:link

Linux:如果你知道端口,你可以使用这个命令:

netstat -plten | grep LISTEN | grep 8080

AIX:

netstat -Aan | grep LISTEN | grep 8080

然后使用第一列(例如:f100050000b05bb8)并运行以下命令:

rmsock f100050000b05bb8 tcpcb

杀死进程。

Git Bash的其他方式:

stopProcessByPortNumber() {
port=":${1}"
portStrLine="$(netstat -ano | findstr LISTENING | findstr $port)"
processId="$(grep -oP '(\d+)(?!.*\d)' <<< $portStrLine)"
echo $processId
taskkill -PID $processId -F
}