我尝试使用来自tomcat /bin目录的./shutdown.sh
关闭Tomcat,但发现服务器未能正确关闭。因此,我无法重新启动。
我的Tomcat正在端口8080
运行。
我想杀掉在8080
端口运行的Tomcat进程。我首先想获取在特定端口(8080)上运行的进程列表,以便选择要终止的进程。
我尝试使用来自tomcat /bin目录的./shutdown.sh
关闭Tomcat,但发现服务器未能正确关闭。因此,我无法重新启动。
我的Tomcat正在端口8080
运行。
我想杀掉在8080
端口运行的Tomcat进程。我首先想获取在特定端口(8080)上运行的进程列表,以便选择要终止的进程。
只需运行此命令。不要忘记将portnumber
替换为您的端口号 ;)
kill -9 $(sudo lsof -t -i:portnumber)
kill -9 `fuser 8080/tcp|xargs -n 1`
命令可以杀死监听TCP连接端口8080的进程。
sudo apt-get install psmisc (or sudo yum install psmisc)
sudo fuser 80/tcp
结果: 80/tcp:1858、1867、1868、1869、1871
逐个杀死进程
kill -9 1858
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
我正在处理一个Yocto Linux系统,该系统可用的Linux工具集非常有限。我想要停止使用特定端口(1883)的进程。
首先,为了查看我们正在监听哪些端口,我使用了以下命令:
root@root:~# netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:hostmon 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdomain:domain 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN
tcp 0 0 :::hostmon :::* LISTEN
tcp 0 0 localhost:domain :::* LISTEN
tcp 0 0 :::ssh :::* LISTEN
tcp 0 0 :::1883 :::* LISTEN
接下来,我通过以下方式找到了使用1883端口的进程名称:
root@root:~# fuser 1883/tcp
290
root@root:~# ps | grep 290
290 mosquitt 25508 S /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
12141 root 8444 S grep 290
从上面可以看到,使用端口1883的是程序/usr/sbin/mosquitto
。
最后,我杀掉了该进程:
root@root:~# systemctl stop mosquitto
我使用了systemctl
,因为在这种情况下它是一个systemd服务。
netstat -lt
fuser <端口号>/tcp
kill <进程ID>
这些命令对我有效:
ps -aux | grep 8000
然后:
sudo kill <PID>
使用 Git Bash 的另一种方式:
stopProcessByPortNumber() {
port=":${1}"
portStrLine="$(netstat -ano | findstr LISTENING | findstr $port)"
processId="$(grep -oP '(\d+)(?!.*\d)' <<< $portStrLine)"
echo $processId
taskkill -PID $processId -F
}
在我的情况下,CentOS 在建议的答案中存在一些问题。因此我使用了以下解决方案:
ss -tanp | grep 65432 | head -1 | grep -Po "(?<=pid=).*(?=,)" | xargs kill
这对我在Mac上有效
sudo kill -9 $(netstat -vnap tcp | grep PORT | awk -F " " '{print $9}')