如何在Linux中杀死运行在特定端口上的进程?

时间:2021-07-29 11:20:45

I tried to close the tomcat using ./shutdown.sh from tomcat /bin directory. But found that the server was not closed properly. And thus I was unable to restart
My tomcat is running on port 8080.

我试图关闭tomcat。/关闭。sh来自tomcat /bin目录。但是发现服务器没有正确关闭。因此,我无法重启我的tomcat在端口8080上运行。

I want to kill the tomcat process running on 8080. I first want to have the list of processes running on a specific port (8080) in order to select which process to kill.

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

14 个解决方案

#1


519  

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. More universal is use of lsof -i4 (or 6 for IPv6).

只在Linux上。更普遍的是使用lsof -i4(或IPv6)。

#2


256  

To list any process listening to the port 8080:

要列出监听端口8080的任何进程:

lsof -i:8080

To kill any process listening to the port 8080:

要杀死监听端口8080的任何进程:

kill $(lsof -t -i:8080)

or more violently:

或更多暴力:

kill -9 $(lsof -t -i:8080)

#3


172  

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. Now use kill command to kill the process

前面的数字是一个进程id,现在使用kill命令来杀死进程。

kill -9 16085

-9 implies the process will be killed forcefully.

-9意味着这个过程将被强有力地杀死。

#4


88  

You can use the lsof command. Let port number like here is 8090

您可以使用lsof命令。这里的端口号是8090。

lsof -i:8090

This command returns a list of open processes on this port.

此命令返回此端口上的打开进程列表。

Something like…

之类的……

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 75782 eoin 5u IPv6 0x01c1c234 0t0 TCP localhost:8090 (LISTEN)

To free the port, kill the process using it(the process id is 75782)…

为了释放端口,使用它杀死进程(进程id为75782)…

kill -9 75782

This one worked for me. here is the link from the original post: link

这个对我起作用了。这里是链接的原始帖子:链接。

#5


57  

I would add this one-liner for only LISTEN on specific port:

我只会在特定的端口上添加这一行代码:

kill -9 $(lsof -t -i:3000 -sTCP:LISTEN)

kill -9 $(lsof -t -i:3000 -sTCP:听)

#6


35  

This prints to stdout the process ids of everything running on <port_number>:

此打印输出到stdout的进程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:

然后我们可以向kill命令提供这些进程id:

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)
}

#7


26  

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. Easily killed.

您将得到该过程的描述。现在使用kill或kill -9 pid。容易死亡。

e.g

netstat -ap | grep :8080

netstat -ap | grep:8080。

tcp6       0      0 :::8080       :::*    LISTEN      1880/java 

Now:

现在:

kill -9 1880

Remember to run all commands as root

记住要以root身份运行所有命令。

#8


14  

try like this,

这样的尝试,

 sudo fuser -n tcp -k 8080

#9


9  

  1. lsof -i tcp:8000 This command lists the information about process running in port 8000

    lsof -i tcp:8000此命令列出了在端口8000中运行的进程的信息。

  2. kill -9 [PID] This command kills the process

    kill -9 [PID]这个命令杀死进程。

#10


6  

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.

杀死进程。

#11


5  

kill -9 `fuser 8080/tcp|xargs -n 1`, this commands also kills the process that listens on port 8080 with TCP connection

kill -9 ' fuser 8080/tcp|xargs -n 1 ',这个命令也会杀死监听端口8080的进程。

#12


3  

Linux: First you can find PID of this command if you know the port :

Linux:如果你知道这个端口的话,首先你可以找到这个命令的PID。

netstat -tulpn 

example:-

例子:-

 Local Address  Foreign Address  State    PID/Program name

  :::3000       :::*             LISTEN    15986/node 

You then take the kill process. run the following command:

然后你就可以进行杀戮了。运行以下命令:

kill -9 PID

kill - 9 PID

Expample: -

Expample:-

kill -9 15986

kill - 9 15986

#13


0  

to build on what @veer7 said:

要建立在@veer7所说的基础之上:

if you want to know what was on the port, do this before you kill it.

如果你想知道港口是什么,在你杀死它之前先做这个。

$ sudo netstat -plten |grep java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      1000       906726      25296/java      
tcp6       0      0 :::8009                 :::*                    LISTEN      1000       907503      25296/java      
tcp6       0      0 :::8080                 :::*                    LISTEN      1000       907499      25296/java      
$ ps 25296
  PID TTY      STAT   TIME COMMAND
25296 ?        Sl     0:16 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Dcatalina.base=/hom

Use 'ps' and the number of the process that netstat reported back

使用“ps”和netstat报告的进程数量。

#14


-2  

In Windows, it will be netstat -ano | grep "8080" and we get the following message TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 10076

在Windows中,它将是netstat -ano | grep“8080”,我们得到了以下消息TCP 0.0.0.0:8080 0.0.0: 0.0.0.0.0: 0.0.0. 0.0.0。

WE can kill the PID using taskkill /F /PID 10076

我们可以使用taskkill /F /PID 10076来杀死PID。

#1


519  

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. More universal is use of lsof -i4 (or 6 for IPv6).

只在Linux上。更普遍的是使用lsof -i4(或IPv6)。

#2


256  

To list any process listening to the port 8080:

要列出监听端口8080的任何进程:

lsof -i:8080

To kill any process listening to the port 8080:

要杀死监听端口8080的任何进程:

kill $(lsof -t -i:8080)

or more violently:

或更多暴力:

kill -9 $(lsof -t -i:8080)

#3


172  

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. Now use kill command to kill the process

前面的数字是一个进程id,现在使用kill命令来杀死进程。

kill -9 16085

-9 implies the process will be killed forcefully.

-9意味着这个过程将被强有力地杀死。

#4


88  

You can use the lsof command. Let port number like here is 8090

您可以使用lsof命令。这里的端口号是8090。

lsof -i:8090

This command returns a list of open processes on this port.

此命令返回此端口上的打开进程列表。

Something like…

之类的……

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 75782 eoin 5u IPv6 0x01c1c234 0t0 TCP localhost:8090 (LISTEN)

To free the port, kill the process using it(the process id is 75782)…

为了释放端口,使用它杀死进程(进程id为75782)…

kill -9 75782

This one worked for me. here is the link from the original post: link

这个对我起作用了。这里是链接的原始帖子:链接。

#5


57  

I would add this one-liner for only LISTEN on specific port:

我只会在特定的端口上添加这一行代码:

kill -9 $(lsof -t -i:3000 -sTCP:LISTEN)

kill -9 $(lsof -t -i:3000 -sTCP:听)

#6


35  

This prints to stdout the process ids of everything running on <port_number>:

此打印输出到stdout的进程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:

然后我们可以向kill命令提供这些进程id:

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)
}

#7


26  

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. Easily killed.

您将得到该过程的描述。现在使用kill或kill -9 pid。容易死亡。

e.g

netstat -ap | grep :8080

netstat -ap | grep:8080。

tcp6       0      0 :::8080       :::*    LISTEN      1880/java 

Now:

现在:

kill -9 1880

Remember to run all commands as root

记住要以root身份运行所有命令。

#8


14  

try like this,

这样的尝试,

 sudo fuser -n tcp -k 8080

#9


9  

  1. lsof -i tcp:8000 This command lists the information about process running in port 8000

    lsof -i tcp:8000此命令列出了在端口8000中运行的进程的信息。

  2. kill -9 [PID] This command kills the process

    kill -9 [PID]这个命令杀死进程。

#10


6  

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.

杀死进程。

#11


5  

kill -9 `fuser 8080/tcp|xargs -n 1`, this commands also kills the process that listens on port 8080 with TCP connection

kill -9 ' fuser 8080/tcp|xargs -n 1 ',这个命令也会杀死监听端口8080的进程。

#12


3  

Linux: First you can find PID of this command if you know the port :

Linux:如果你知道这个端口的话,首先你可以找到这个命令的PID。

netstat -tulpn 

example:-

例子:-

 Local Address  Foreign Address  State    PID/Program name

  :::3000       :::*             LISTEN    15986/node 

You then take the kill process. run the following command:

然后你就可以进行杀戮了。运行以下命令:

kill -9 PID

kill - 9 PID

Expample: -

Expample:-

kill -9 15986

kill - 9 15986

#13


0  

to build on what @veer7 said:

要建立在@veer7所说的基础之上:

if you want to know what was on the port, do this before you kill it.

如果你想知道港口是什么,在你杀死它之前先做这个。

$ sudo netstat -plten |grep java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      1000       906726      25296/java      
tcp6       0      0 :::8009                 :::*                    LISTEN      1000       907503      25296/java      
tcp6       0      0 :::8080                 :::*                    LISTEN      1000       907499      25296/java      
$ ps 25296
  PID TTY      STAT   TIME COMMAND
25296 ?        Sl     0:16 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Dcatalina.base=/hom

Use 'ps' and the number of the process that netstat reported back

使用“ps”和netstat报告的进程数量。

#14


-2  

In Windows, it will be netstat -ano | grep "8080" and we get the following message TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 10076

在Windows中,它将是netstat -ano | grep“8080”,我们得到了以下消息TCP 0.0.0.0:8080 0.0.0: 0.0.0.0.0: 0.0.0. 0.0.0。

WE can kill the PID using taskkill /F /PID 10076

我们可以使用taskkill /F /PID 10076来杀死PID。