如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
当前回答
如果你想使用Python:检查是否可以在Python中杀死正在监听特定端口的进程,例如8080?
Smunk给出的答案很好。我在这里重复他的密码:
from psutil import process_iter
from signal import SIGTERM # or SIGKILL
for proc in process_iter():
for conns in proc.connections(kind='inet'):
if conns.laddr.port == 8080:
proc.send_signal(SIGTERM) # or SIGKILL
continue
其他回答
在Windows PowerShell版本1或更高版本中停止端口3000上的进程:
Stop-Process (,(netstat -ano | findstr:3000).split() | foreach {$[$.length-1]}) -Force
根据@morganpdx的建议,这里有一个更像powershell的更好的版本:
Stop-Process -Id (get - netttcpconnection -LocalPort 3000)。OwningProcess force
我在Windows上运行zookeeper,无法使用zookeeper-stop.sh停止在2181端口运行的zookeeper,所以尝试了这个双斜线“//”方法来kill任务。它工作
1. netstat -ano | findstr :2181
TCP 0.0.0.0:2181 0.0.0.0:0 LISTENING 8876
TCP [::]:2181 [::]:0 LISTENING 8876
2.taskkill //PID 8876 //F
SUCCESS: The process with PID 8876 has been terminated.
如果你可以在Windows上使用PowerShell,你只需要:
Get-Process -Id (Get-NetTCPConnection -LocalPort "8080").OwningProcess | Stop-Process
我知道这是一个很老的问题,但发现很容易记住,快速命令杀死使用端口的应用程序。
要求:npm@5.2.0^版本
npx kill-port 8080
你也可以在这里阅读更多关于kill-port的内容:https://www.npmjs.com/package/kill-port
第一步(与KavinduWije所写的接受答案相同):
netstat -ano | findstr:yourPortNumber
第2步更改为:
tskill typeyourPIDhere
注意:taskkill在某些git bash终端中不起作用