我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。
我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。
我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。
我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。
当前回答
首先检查进程netstat -lt 检查进程id fuser <端口号>/tcp Kill <进程id>
其他回答
选项1在特定端口上只杀死LISTEN的一行程序:
kill -9 $(lsof -t -i:3000 -sTCP:LISTEN)
选项2如果你安装了npm,你也可以运行
npx kill-port 3000
输出所有在<port_number>上运行的进程id:
fuser -n tcp <port_number>
它还输出一些东西到stderr,所以:
fuser -n tcp <port_number> 2> /dev/null
然后我们可以将这些进程id提供给kill命令:
sudo kill $(fuser -n tcp <port_number> 2> /dev/null)
如果你经常这样做,你也可以把它放在一个函数中:
function killport() {
sudo kill $(fuser -n tcp $1 2> /dev/null)
}
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
}
在我的情况下,cent os在建议的答案中有一些问题。所以我使用了以下解决方案:
ss -tanp | grep 65432 | head -1 | grep -Po "(?<=pid=).*(?=,)" | xargs kill