我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。
我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。
我尝试在tomcat /bin目录下使用。/shutdown.sh关闭tomcat。但发现服务器没有正确关闭。因此我无法重新启动我的tomcat运行在端口8080上。
我想终止在8080上运行的tomcat进程。我首先想要在特定端口(8080)上运行的进程列表,以便选择要终止哪个进程。
当前回答
首先你需要做的是运行(替换为你的端口号):
fuser -k 3000/tcp
这将释放端口。运行上述命令后,执行以下命令:
service docker restart
你的问题解决了。
其他回答
我正在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/ mosquito。
最后,我终止了这个过程:
root@root:~# systemctl stop mosquitto
我使用systemctl,因为在这种情况下,它是一个systemd服务。
Linux:如果你知道端口,你可以使用这个命令:
netstat -plten | grep LISTEN | grep 8080
AIX:
netstat -Aan | grep LISTEN | grep 8080
然后使用第一列(例如:f100050000b05bb8)并运行以下命令:
rmsock f100050000b05bb8 tcpcb
杀死进程。
使用命令
sudo netstat -plten |grep java
使用grep Java作为tomcat使用Java作为他们的进程。
它将显示带有端口号和进程id的进程列表
tcp6 0 0 :::8080 :::* LISTEN
1000 30070621 16085/java
“/java”前面的数字是进程号。现在使用kill命令终止进程
kill -9 16085
-9表示进程将被强制终止。
要知道某个端口上运行的服务的pid:
netstat -tulnap | grep :*port_num*
您将得到该过程的描述。现在使用kill或kill -9 pid。容易死亡。
e.g
Netstat -ap | grep:8080
tcp6 0 0 :::8080 :::* LISTEN 1880/java
Now:
kill -9 1880
记住以root用户运行所有命令
Git Bash的其他方式:
stopProcessByPortNumber() {
port=":${1}"
portStrLine="$(netstat -ano | findstr LISTENING | findstr $port)"
processId="$(grep -oP '(\d+)(?!.*\d)' <<< $portStrLine)"
echo $processId
taskkill -PID $processId -F
}