我试图在命令行中为ubuntu中的特定端口终止进程。

如果我运行此命令,我将获得端口:

sudo lsof -t -i:9001

所以…现在我想跑:

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

我收到以下错误消息:

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.

我也尝试过杀“lsof-t-I:9001”


当前回答

它给我一个错误OSError:[Errno 98]地址已经在使用中。使用以下方法解决了我在Ubuntu中的错误。(版本=“18.04.4 LTS(仿生海狸)”)

$ sudo netstat -lpn |grep :5000
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      25959/uwsgi   

$ fuser -k -n tcp 5000
5000/tcp:            25959
 

希望它能帮助到某人!

其他回答

只需在终端中输入以下命令

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

为了首先终止基于端口的进程,我们必须找到给定端口的相关pid,

在我的例子中,我想获得3000端口的pid(进程id):

netstat -ltnp | grep -w '3000'

然后找到正在侦听tcp的pid

tcp6       0      0 :::3000                 :::*                    LISTEN      29972/node  

你会得到pid 29972

要终止此pid,请使用以下命令

kill -9 29972

基于端口的kill进程伪码

 netstat -ltnp | grep -w 'PORT'

and

kill -9 PID

你可以使用

fuser -n tcp -k 9001 

在维基百科中查看更多详细信息

试试看:

lsof -i :port

or 

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

or

kill -9 <pid>

or 

sh killport 8000

要终止在端口号9001上运行的进程

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


lsof   - list of files(Also used for to list related processes)

-t     - show only process ID

-i     - show only internet connections related process

:9001  - show only processes in this port number

kill   - command to kill the process

-9     - forcefully

sudo   - command to ask admin privilege(user id and password).

有关更多信息,请访问我的博客