如何在ubuntu的一个端口上杀死一个进程?

时间:2022-08-29 14:50:24

I am trying to kill a proccess in the command line for a specific port in ubuntu.

我试图在ubuntu的命令行中杀死一个进程。

If I run this command I get the port:

如果我运行这个命令,我得到端口:

sudo lsof -t -i:9001

so...now I want to run:

所以…现在我想跑:

sudo kill 'sudo lsof -t -i:9001'

I get this error message:

我得到这个错误信息:

ERROR: garbage process ID "lsof -t -i:9001".
Usage:
  kill pid ...              Send SIGTERM to every process listed.
  kill signal pid ...       Send a signal to every process listed.
  kill -s signal pid ...    Send a signal to every process listed.
  kill -l                   List all signal names.
  kill -L                   List all signal names in a nice table.
  kill -l signal            Convert between signal numbers and names.

I tried sudo kill 'lsof -t -i:9001' as well

我也试过用sudo kill 'lsof -t -i:9001'。

13 个解决方案

#1


389  

You want to use backtick not regular tick:

你想用backtick而不是regular tick:

sudo kill `sudo lsof -t -i:9001`

If that doesn't work you could also use $() for command interpolation:

如果这不起作用,您还可以使用$()用于命令内插:

sudo kill $(sudo lsof -t -i:9001)

#2


120  

you can use

您可以使用

fuser -n tcp -k 9001 

see more details in wikipedia

请参阅wikipedia中的详细信息。

#3


36  

FOR UBUNTU 1- Find what application/process is using the pro, type:

对于UBUNTU 1-找到应用程序/进程使用的是pro,类型:

sudo netstat -lpn |grep :8080

and press Enter.

并按Enter键。

You will get an output similar to this one

您将得到与此类似的输出。

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

2- I have got the process Id, which is 6782, now this is the process that is using port 8080.

2-我已经得到了进程Id,它是6782,现在这是使用端口8080的进程。

3- Kill the process, type:kill 6782

3-杀死过程,类型:杀死6782。

kill 6782

#4


25  

There are some process which does not shown using normal netstat command, so you have to check it using sudo.

有一些进程没有使用常规netstat命令显示,所以您必须使用sudo检查它。

Do sudo netstat -lpn |grep :8080. Process running by system does not show PID, to get PID of this process you will have to run it using sudo

做sudo netstat -lpn |grep:8080。由系统运行的进程不显示PID,为了得到这个过程的PID,您将不得不使用sudo运行它。

And then killl the process using port 8080. You may have to use sudo here as well. So to kill this process use sudo kill -9 PID

然后用8080端口将这个过程完成。你也可以在这里使用sudo。所以杀死这个过程使用sudo kill -9 PID。

#5


16  

Use killport command :

使用killport命令:

sh killport 9001 

To Download shell ,you can use wget :

要下载shell,您可以使用wget:

wget https://cdn.rawgit.com/abdennour/miscs.sh/e0aac343/killport

#6


11  

You may also use fuser to do that (sends SIGKILL by default): sudo fuser -k 9001/tcp

您还可以使用fuser来执行(默认发送SIGKILL): sudo fuser - k9001 /tcp。

#7


8  

The best way to kill a port in ubuntu terminal is fuser -k 9001/tcp

在ubuntu终端中杀死一个端口的最好方法是fuser - k9001 /tcp。

#8


6  

Use this:

用这个:

sudo kill -9 $(lsof -t -i:9001)

#9


4  

Kill PORT:

杀死端口:

sudo is important to show process id.

sudo对于显示进程id很重要。

$ sudo netstat -antlp | grep 45136
tcp      0      0 0.0.0.0:45136         0.0.0.0:*        LISTEN           **-** 

$ kill -9 45136

#10


3  

Use the command

使用命令

 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意味着这个过程将被强有力地杀死。

#11


2  

Use this for killing process which is running on port number "9001"

使用这个用于杀死在端口号“9001”上运行的进程

 kill $(lsof -t -i:9001)

#12


2  

Try this:

试试这个:

lsof -i :port

or 

sudo kill $(sudo lsof -t -i:8000)

or

kill -9 <pid>

or 

sh killport 8000

#13


1  

sudo kill `sudo lsof -t -i:9001`

you don't have to add the -9signal option

你不需要添加-9signal选项。

#1


389  

You want to use backtick not regular tick:

你想用backtick而不是regular tick:

sudo kill `sudo lsof -t -i:9001`

If that doesn't work you could also use $() for command interpolation:

如果这不起作用,您还可以使用$()用于命令内插:

sudo kill $(sudo lsof -t -i:9001)

#2


120  

you can use

您可以使用

fuser -n tcp -k 9001 

see more details in wikipedia

请参阅wikipedia中的详细信息。

#3


36  

FOR UBUNTU 1- Find what application/process is using the pro, type:

对于UBUNTU 1-找到应用程序/进程使用的是pro,类型:

sudo netstat -lpn |grep :8080

and press Enter.

并按Enter键。

You will get an output similar to this one

您将得到与此类似的输出。

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

2- I have got the process Id, which is 6782, now this is the process that is using port 8080.

2-我已经得到了进程Id,它是6782,现在这是使用端口8080的进程。

3- Kill the process, type:kill 6782

3-杀死过程,类型:杀死6782。

kill 6782

#4


25  

There are some process which does not shown using normal netstat command, so you have to check it using sudo.

有一些进程没有使用常规netstat命令显示,所以您必须使用sudo检查它。

Do sudo netstat -lpn |grep :8080. Process running by system does not show PID, to get PID of this process you will have to run it using sudo

做sudo netstat -lpn |grep:8080。由系统运行的进程不显示PID,为了得到这个过程的PID,您将不得不使用sudo运行它。

And then killl the process using port 8080. You may have to use sudo here as well. So to kill this process use sudo kill -9 PID

然后用8080端口将这个过程完成。你也可以在这里使用sudo。所以杀死这个过程使用sudo kill -9 PID。

#5


16  

Use killport command :

使用killport命令:

sh killport 9001 

To Download shell ,you can use wget :

要下载shell,您可以使用wget:

wget https://cdn.rawgit.com/abdennour/miscs.sh/e0aac343/killport

#6


11  

You may also use fuser to do that (sends SIGKILL by default): sudo fuser -k 9001/tcp

您还可以使用fuser来执行(默认发送SIGKILL): sudo fuser - k9001 /tcp。

#7


8  

The best way to kill a port in ubuntu terminal is fuser -k 9001/tcp

在ubuntu终端中杀死一个端口的最好方法是fuser - k9001 /tcp。

#8


6  

Use this:

用这个:

sudo kill -9 $(lsof -t -i:9001)

#9


4  

Kill PORT:

杀死端口:

sudo is important to show process id.

sudo对于显示进程id很重要。

$ sudo netstat -antlp | grep 45136
tcp      0      0 0.0.0.0:45136         0.0.0.0:*        LISTEN           **-** 

$ kill -9 45136

#10


3  

Use the command

使用命令

 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意味着这个过程将被强有力地杀死。

#11


2  

Use this for killing process which is running on port number "9001"

使用这个用于杀死在端口号“9001”上运行的进程

 kill $(lsof -t -i:9001)

#12


2  

Try this:

试试这个:

lsof -i :port

or 

sudo kill $(sudo lsof -t -i:8000)

or

kill -9 <pid>

or 

sh killport 8000

#13


1  

sudo kill `sudo lsof -t -i:9001`

you don't have to add the -9signal option

你不需要添加-9signal选项。