This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(30)
您想要使用反引号,而不是常规勾号:
如果这不起作用,您还可以使用
$()
进行命令插值:You want to use backtick, not regular tick:
If that doesn't work, you could also use
$()
for command interpolation:您可以使用
在维基百科中查看更多详细信息
you can use
see more details in wikipedia
对于Ubuntu
1- 查找正在使用 Pro 的应用程序/进程,输入:
并按 Enter。
您将得到类似于此的输出
2- 我已获得进程 ID,即 6782,现在这是使用端口 8080 的进程。
3- 终止该进程,输入:kill -p 6782
FOR UBUNTU
1- Find what application/process is using the pro, type:
and press Enter.
You will get an output similar to this one
2- I have got the process Id, which is 6782, now this is the process that is using port 8080.
3- Kill the process, type: kill -p 6782
在 Ubuntu 终端中终止端口的最佳方法是使用
fuser
命令;例如:默认发送
SIGKILL
。The best way to kill a port in the Ubuntu terminal is with the
fuser
command; e.g.:This sends
SIGKILL
by default.要终止在端口号
9001
上运行的进程,了解更多信息,您可以访问我的博客
To kill a process running on Port number
9001
for more you can visit my blog
有一些进程无法使用普通的 netstat 命令显示,因此您必须使用 sudo 检查它。
执行
sudo netstat -lpn |grep :8080
。系统运行的进程不显示 PID,要获取该进程的 PID,您必须使用 sudo 运行它,然后使用端口 8080 杀死该进程。您可能还必须在此处使用
sudo
。因此,要终止此进程,请使用sudo Kill -9 PID
There are some process which does not shown using normal netstat command, so you have to check it using
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 usingsudo
And then killl the process using port
8080
. You may have to usesudo
here as well. So to kill this process usesudo kill -9 PID
使用 killport 命令:
要下载 shell,您可以使用
wget :
Use killport command :
To Download shell ,you can use
wget
:在 CLI 中添加此代码并使用此别名。
Add this code in your CLI and use this alias.
让我们考虑一下,如果您想终止端口 3000。
第 1 步:运行此命令,这将为您提供其 PID。
返回的 PID 为 291141
第 2 步:运行此命令以使用 PID 终止端口。
繁荣!!!端口被杀死
Lets consider If you want to kill a port 3000.
Step 1: Run this command, which will give u its PID.
This returned me PID as 291141
Step 2: Run this command to kill the port using PID.
Boom!!! Port killed
要首先根据端口终止进程,我们必须找出给定端口的相关 pid 并使用该 pid 终止,
在我的例子中,我想获取 3000 端口的 pid(进程 id):
然后找到正在侦听 tcp 的 pid
你会得到 pid 29972
要杀死这个 pid 使用下面的命令
伪代码来根据端口
和杀死进程
To kill the process based on port first we have to find out the relevant pid for given port and kill using that pid,
In my case i wanted to get the pid(process id) of 3000 port:
then find pid which is listening to tcp
you will get pid 29972
To kill this pid use below command
pseudo code for kill process based on port
and
sudo Kill -9 $(sudo lsof -t -i:9001)
为我工作或您可以
将 9001 替换为您想要的端口号。
sudo kill -9 $(sudo lsof -t -i:9001)
worked for me oryou can use
replace 9001 with port number you want.
使用这个:
Use this:
只需在终端中输入以下命令
Just enter the following command in the terminal
您可以在终端中使用以下命令
熔断器-k 3000/tcp
you can use following command in terminal
fuser -k 3000/tcp
在我的 ubuntu-22.04 机器上,这可以杀死端口 8000:
On my
ubuntu-22.04
machine, this worked to kill port 8000:Kill PORT:
sudo
对于显示进程 ID 很重要。Kill PORT:
sudo
is important to show process id.使用 grep java 命令
,因为 tomcat 使用 java 作为其进程。
它将显示带有端口号和进程 ID 的进程列表,
/java 之前的数字是进程 ID。现在使用kill命令杀死进程
-9表示进程将被强制杀死。
Use the command
used grep java as tomcat uses java as their processes.
It will show the list of processes with port number and process id
the number before /java is a process id. Now use kill command to kill the process
-9 implies the process will be killed forcefully.
如果我是你,我会使用
If I was you,I would use
只需向您的
.bashrc
/.zshrc
添加一个别名:alias kp='kill_process_by_port() { sudo Kill -9 $(sudo lsof -t -i:"$1"); }; Kill_process_by_port "$@"'
Just add an alias to your
.bashrc
/.zshrc
:alias kp='kill_process_by_port() { sudo kill -9 $(sudo lsof -t -i:"$1"); }; kill_process_by_port "$@"'
试试这个:
Try this:
您不必添加
-9
信号选项you don't have to add the
-9
signal option它给我一个错误
OSError:[Errno 98]地址已在使用中
。使用以下方法解决了我在 Ubuntu 中的错误。(VERSION="18.04.4 LTS (Bionic Beaver)"
)希望它会对某人有所帮助!
It gives me an error
OSError: [Errno 98] Address already in use
. using the following method solved my error in Ubuntu.(VERSION="18.04.4 LTS (Bionic Beaver)"
)Hope it will help someone!
然后获取该进程的PID
then get the PID of this process
xargs
可能是一个非常有用的命令。您可以像这样通过管道命令
它的作用:
它获取第一个命令的输出(在本例中是在端口上运行的进程),并将其传递给 sudo kill 。
xargs
can be a very useful command.You can pipe commands like this
What it does:
it takes the output from the first command, in this case the process running on port, and will pass it to
sudo kill
.当使用较新版本的 Ubuntu 时,您将不再使用
netcat
,而是使用ss
When using newer versions of Ubuntu you won't have
netcat
anymore, instead you usess
获取端口3000上运行的进程的PID:
lsof -i tcp:3000
杀死进程
kill -9 process_id
示例:
lsof -i tcp:3000
(输出中的 PID = 5805)
杀死-9 5805
get PID of process running on port 3000:
lsof -i tcp:3000
kill th process
kill -9 process_id
Example:
lsof -i tcp:3000
(PID in output = 5805)
kill -9 5805
它的过程分为两个步骤:
杀死该 ID 8689 的进程(可以是不同的)
<前><代码>fuser -n tcp 8080
#o/p 8080/tcp 8689
杀死-9 8689
Its two steps process:
Kill process of that id 8689 (can be different)
你可以使用节点来完成这个
工作
you can work this using node
then
显示活动的 TCP 连接以及计算机正在侦听的端口。
它会列出 pid 上的所有连接。找到并复制 pid 并运行以下命令。确保在以下命令中将 替换为实际 id。
Displays active TCP connections, ports on which the computer is listening.
It will list you all the connection along pid. Find and copy the pid and run the following command. Make sure you replace the with actual id in the following command.
您还可以使用 xargs。只需运行以下命令:
sudo lsof -t -i:443 | xargs sudo Kill -9
You can also use xargs. Just run the following,
sudo lsof -t -i:443 | xargs sudo kill -9