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

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


当前回答

如果端口上的服务没有响应,如何杀死进程

timeout 1 telnet localhost 8080 2>&1 | if grep -q 'Unable'; then sudo kill -9 $(sudo lsof -t -i:8080); fi

它的作用

启动“timeout”一秒,使telnet退出 ' 2>&1 | '管道错误消息,没有退出 如果错误消息包含'Unable',则运行代码杀死锁定端口8080的进程

这可以放在一个文件中,并从'sudo crontab'定期运行

其他回答

这是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
sudo apt-get install psmisc (or sudo yum install psmisc)
sudo fuser 80/tcp

结果: 80/tcp: 1858 1867 1868 1869 1871

逐个杀死进程

杀死-9 1858

这在mac中很管用

sudo kill -9 $(netstat -vnap tcp | grep PORT | awk -F " " '{print $9}')

首先检查进程netstat -lt 检查进程id fuser <端口号>/tcp Kill <进程id>

只有以下命令对我有用:

ps -aux | grep 8000

然后:

sudo kill <PID>