本文翻译自:How to kill a process running on particular port in Linux?
I tried to close the tomcat using ./shutdown.sh
from tomcat /bin
directory. 我试图使用tomcat /bin
目录中的./shutdown.sh
关闭tomcat。 But found that the server was not closed properly. 但是发现服务器没有正确关闭。 And thus I was unable to restart 因此我无法重新启动
My tomcat is running on port 8080
. 我的tomcat在端口8080
上运行。
I want to kill the tomcat process running on 8080
. 我想杀死运行在8080
上的tomcat进程。 I first want to have the list of processes running on a specific port (8080) in order to select which process to kill. 我首先要具有在特定端口(8080)上运行的进程的列表,以便选择要杀死的进程。
#1楼
参考:https://stackoom.com/question/mbPe/如何终止在Linux中特定端口上运行的进程
#2楼
Use the command 使用命令
sudo netstat -plten |grep java
used grep java
as tomcat
uses java
as their processes. 使用grep java
作为tomcat
使用java
作为其进程。
It will show the list of processes with port number and process id 它将显示带有端口号和进程ID的进程列表
tcp6 0 0 :::8080 :::* LISTEN
1000 30070621 16085/java
the number before /java
is a process id. /java
之前的数字是进程ID。 Now use kill
command to kill the process 现在使用kill
命令杀死进程
kill -9 16085
-9
implies the process will be killed forcefully. -9
表示该过程将被强制终止。
#3楼
This fuser 8080/tcp
will print you PID of process bound on that port. 此fuser 8080/tcp
将为您打印该端口上绑定的进程的PID。
And this fuser -k 8080/tcp
will kill that process. 而这个fuser -k 8080/tcp
将终止该进程。
Works on Linux only. 仅适用于Linux。 More universal is use of lsof -i4
(or 6 for IPv6). 更通用的是使用lsof -i4
(对于IPv6, lsof -i4
6)。
#4楼
This prints to stdout the process ids of everything running on <port_number>
: 这将打印以输出在<port_number>
上运行的所有进程的进程ID:
fuser -n tcp <port_number>
It also prints some stuff to stderr, so: 它还会向stderr打印一些内容,因此:
fuser -n tcp <port_number> 2> /dev/null
We can then supply these process ids to the kill
command: 然后,我们可以将这些进程ID提供给kill
命令:
sudo kill $(fuser -n tcp <port_number> 2> /dev/null)
You could also put this in a function if you do it a lot: 如果您经常这样做,也可以将其放在函数中:
function killport() {
sudo kill $(fuser -n tcp $1 2> /dev/null)
}
#5楼
Linux : You can use this command if you know the port : Linux :如果知道端口,则可以使用此命令:
netstat -plten | grep LISTEN | grep 8080
AIX : AIX :
netstat -Aan | grep LISTEN | grep 8080
You then take the first column (example: f100050000b05bb8) and run the following command: 然后,您选择第一列(例如:f100050000b05bb8)并运行以下命令:
rmsock f100050000b05bb8 tcpcb
kill process. 杀死进程。
#6楼
To know the pid of service running on particular port : 要知道在特定端口上运行的服务的pid:
netstat -tulnap | grep :*port_num*
you will get the description of that process. 您将获得该过程的描述。 Now use kill or kill -9 pid. 现在使用kill或kill -9 pid。 Easily killed. 容易被杀死。
eg 例如
netstat -ap | grep :8080
tcp6 0 0 :::8080 :::* LISTEN 1880/java
Now: 现在:
kill -9 1880
Remember to run all commands as root
记住要以root
身份运行所有命令