我试图在命令行中为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”


当前回答

获取端口3000上运行的进程的PID:lsof-i tcp:3000压井工艺kill-9进程id

例子:lsof-i tcp:3000(输出PID=5805)杀死-9 5805

如果需要,使用sudo

其他回答

要终止在端口号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).

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

使用此项:

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

终止端口:

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

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

$ kill -9 45136

显示活动的TCP连接、计算机正在侦听的端口。

netstat -tupln

它将列出pid中的所有连接。查找并复制pid,然后运行以下命令。确保在以下命令中将替换为实际id。

kill -9 <copied pid>

-9用于强制终止连接。

只需将别名添加到.bashrc/.zshrc:

打开新终端纳米bashrc向下滚动并添加别名:alias kp='sudo kill-9` sudo lsof-t-i:“$1”`'ctrl+x+y源.bashrc9000 kp