简体   繁体   English

我怎样才能杀死任何正在使用端口 8080 的进程,以便我可以启动 vagrant? [关闭]

[英]How can I kill whatever process is using port 8080 so that I can vagrant up? [closed]

On MacOSX, I'm using Packer to build a Vagrant box so I need to continually bring it up and tear it down.在 MacOSX 上,我正在使用 Packer 构建一个 Vagrant 框,因此我需要不断地启动和拆卸它。 I'm attempting to 'vagrant up', and receive the standard error because the port is in use:我正在尝试“流浪起来”,并收到标准错误,因为该端口正在使用中:

"Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 8080 is already in use on the host machine." “Vagrant 无法转发此 VM 上的指定端口,因为它们会与已经侦听这些端口的其他应用程序发生冲突。转发到 8080 的端口已在主机上使用。”

The solution seems simple enough: I just need to identify the process that is holding port 8080 open and kill that process, right?.解决方案似乎很简单:我只需要确定打开 8080 端口的进程并终止该进程,对吗? It's not that easy.它不是那么容易。


If I run the command:如果我运行命令:

nmap localhost -p 8080

I receive the following output:我收到以下 output:

PORT     STATE SERVICE
8080/tcp open  http-proxy

If I run the following command:如果我运行以下命令:

top -o prt

The highest port in use in 1360 1360 中使用的最高端口


If I run the following command:如果我运行以下命令:

 netstat -tulpn | grep :8080

I receive:我收到:

netstat: n: unknown or uninstrumented protocol

If I run the following command:如果我运行以下命令:

lsof -i :8080

I receive no output我没有收到 output


If I restart my computer, the port is now available and I can now 'vagrant up'.如果我重新启动计算机,该端口现在可用,我现在可以“游荡”。

How can I kill whatever process is using port 8080 so that I can vagrant up without restarting my computer?我怎样才能杀死任何正在使用端口 8080 的进程,这样我就可以在不重新启动计算机的情况下启动 vagrant?

This might help这可能有帮助

lsof -n -i4TCP:8080 

The PID is the second field in the output. PID 是输出中的第二个字段。

Or try:或尝试:

lsof -i -P

Fast and quick solution:快速快速的解决方案:

lsof -n -i4TCP:8080

PID is the second field. PID是第二个字段。 Then, kill that process:然后,杀死该进程:

kill -9 PID

Less fast but permanent solution速度较慢但永久的解决方案

  1. Go to /usr/local/bin/ (Can use command+shift+g in finder)转到/usr/local/bin/ (可以在finder中使用command+shift+g)

  2. Make a file named stop .制作一个名为stop的文件。 Paste the below code in it:将以下代码粘贴到其中:

#!/bin/bash
touch temp.text
lsof -n -i4TCP:$1 | awk '{print $2}' > temp.text
pidToStop=`(sed '2q;d' temp.text)`
> temp.text
if [[ -n $pidToStop ]]
then
kill -9 $pidToStop
echo "Congrates!! $1 is stopped."
else
echo "Sorry nothing running on above port"
fi
rm temp.text
  1. Save this file.保存此文件。
  2. Make the file executable chmod 755 stop使文件可执行chmod 755 stop
  3. Now, go to terminal and write stop 8888 (or any port)现在,转到终端并写入stop 8888 (或任何端口)

In case above-accepted answer did not work, try below solution.如果以上接受的答案不起作用,请尝试以下解决方案。 You can use it for port 8080 or for any other ports.您可以将它用于端口 8080 或任何其他端口。

sudo lsof -i tcp:3000 

Replace 3000 with whichever port you want.将 3000 替换为您想要的任何端口。 Run below command to kill that process.运行以下命令以终止该进程。

sudo kill -9 PID

PID is process ID you want to kill. PID 是您要杀死的进程 ID。

Below is the output of commands on mac Terminal.以下是 mac 终端上的命令输出。

命令输出

To script this:要编写此脚本:

pid=$(lsof -ti tcp:8080)
if [[ $pid ]]; then
  kill -9 $pid
fi

The -t argument makes the output of lsof "terse" which means that it only returns the PID. -t参数使 lsof 的输出“简洁”,这意味着它只返回 PID。

sudo lsof -i:8080

By running the above command you can see what are all the jobs running.通过运行上面的命令,您可以看到所有正在运行的作业。

kill -9 <PID Number>

Enter the PID (process identification number), so this will terminate/kill the instance.输入 PID(进程标识号),这样将终止/终止实例。

I needed to run this command我需要运行这个命令

sudo lsof -i :80 # checks port 8080

Then i got然后我得到了

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
acwebseca 312 root   36u  IPv4 0x34ae935da20560c1      0t0  TCP 192.168.1.3:50585->104.25.53.12:http (ESTABLISHED)

show which service is using the PID显示哪个服务正在使用 PID

ps -ef 312

Then I got this然后我得到了这个

  UID   PID  PPID   C STIME   TTY           TIME CMD
    0   312    58   0  9:32PM ??         0:02.70 /opt/cisco/anyconnect/bin/acwebsecagent -console

To uninstall cisco web security agent run卸载思科网络安全代理运行

sudo /opt/cisco/anyconnect/bin/websecurity_uninstall.sh

credits to: http://tobyaw.livejournal.com/315396.html归功于: http : //tobyaw.livejournal.com/315396.html

I needed to kill processes on different ports so I created a bash script:我需要杀死不同端口上的进程,所以我创建了一个 bash 脚本:

killPort() {
  PID=$(echo $(lsof -n -i4TCP:$1) | awk 'NR==1{print $11}')
  kill -9 $PID
}

Just add that to your .bashrc and run it like this:只需将它添加到您的 .bashrc 并像这样运行它:

killPort 8080

You can pass whatever port number you wish你可以传递任何你想要的端口号

It can be Cisco AnyConnect.它可以是 Cisco AnyConnect。 Check if /Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist exists.检查 /Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist 是否存在。 Then unload it with launchctl and delete from /Library/LaunchDaemons然后用launchctl卸载它并从/Library/LaunchDaemons中删除

您还可以使用活动监视器来识别和退出使用端口的进程。

Run: nmap -p 8080 localhost (Install nmap with MacPorts or Homebrew if you don't have it on your system yet)运行: nmap -p 8080 localhost (如果你的系统上还没有安装 nmap 与 MacPorts 或 Homebrew)

Nmap scan report for localhost (127.0.0.1)本地主机 (127.0.0.1) 的 Nmap 扫描报告

Host is up (0.00034s latency).主机已启动(0.00034 秒延迟)。

Other addresses for localhost (not scanned): ::1本地主机的其他地址(未扫描):::1

PORT STATE SERVICE港口国服务

8080/tcp open http-proxy 8080/tcp 打开http-proxy

Run: ps -ef | grep http-proxy运行: ps -ef | grep http-proxy ps -ef | grep http-proxy

UID PID PPID C STIME TTY TIME CMD UID PID PPID C STIME TTY TIME CMD

640 99335 88310 0 12:26pm ttys002 0:00.01 grep http-proxy" 640 99335 88310 0 12:26pm ttys002 0:00.01 grep http-proxy”

Run: ps -ef 640 (replace 501 with your UID)运行: ps -ef 640 (用你的 UID 替换 501)

/System/Library/PrivateFrameworks/PerformanceAnalysis.framework/Versions/A/XPCServices/com.apple.PerformanceAnalysis.animationperfd.xpc/Contents/MacOS/com.apple.PerformanceAnalysis.animationperfd /System/Library/PrivateFrameworks/PerformanceAnalysis.framework/Versions/A/XPCServices/com.apple.PerformanceAnalysis.animationperfd.xpc/Contents/MacOS/com.apple.PerformanceAnalysis.animationperfd

Port 8080 on mac osx is used by something installed with XCode SDK mac osx 上的端口 8080 被使用XCode SDK 安装的东西使用

try netstat试试 netstat

netstat -vanp tcp | grep 3000

if your netstat doesn't support -p , use lsof如果您的 netstat 不支持 -p ,请使用 lsof

sudo lsof -i tcp:3000 

For Centos 7 use Centos 7 使用

netstat -vanp --tcp | grep 3000

Use the following command:使用以下命令:

lsof -n -i4TCP:8080 | awk '{print$2}' | xargs kill -9

The process id of port 8080 will be picked and killed forcefully using kill -9 .端口 8080 的进程 id 将被使用kill -9强行选择和杀死。

After referring to the solution of @voutasaurus.参考@voutasaurus的解决方案后。 I wrote this utility to simplify the process of killing all the processes that are running on the port.我编写这个实用程序是为了简化杀死端口上运行的所有进程的过程。

killProcessesUsing3000 () {
  pid=$(lsof -ti :3000)  # The -t argument makes the output of lsof "terse" (Brief) which means that it only returns the PID.
  # PID contains process processes that run on the 3000 port. In new lines if they are multiples
  for num ($=pid) {
    echo $num
    kill -9 $num
  }
}

#Alias
alias kill3000="killProcessesUsing3000"

For me this worked对我来说这很有效

Open your mac terminal打开你的 mac 终端

kill $(lsof -t -i:8080)

Explanation:解释:

lsof -t returns the PID and passes that to kill. lsof -t返回 PID 并将其传递给 kill。

I tried many of the above and they didn't work for me.我尝试了上面的许多方法,但它们对我不起作用。

After many hours, I found this one liner:几个小时后,我找到了这个班轮:

# kill 8080
alias nuke88="lsof -i tcp:8080 | grep LISTEN | awk '{print \$2}' | xargs kill"

# kill 3000
alias nuke3k="lsof -i tcp:3000 | grep LISTEN | awk '{print \$2}' | xargs kill"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何杀死每次在 Mac 上重新启动的进程? - How can I kill a process that restart itself each time on Mac? 我该如何杀死其父为PID = 0的僵尸进程? - How can I kill a zombie process whose parent is PID = 0? 如何清除目标端口上运行的进程? - How can I clear the process running on my target port? 如何在Linux Vagrant VM内设置桌面用户,使其表现为具有通常用户名,ssh键等的标准工具控制台? - How can I set up my desktop user inside a Linux Vagrant VM so that it behaves like a standard tools console with my usual username, ssh keys, etc.? 每次我的OSX机器启动时,如何自动完成流浪? - How can I automatically do vagrant up every time my OSX machine boots? 进程在调试器中崩溃; 我怎么杀死它 - Process crashed in debugger; how do I kill it 如何在 Vagrant 下运行 OSX El Capitan Box? - How can I run an OSX El Capitan Box under Vagrant? 如何使用Python CGI脚本杀死启动该脚本的浏览器? - How can I use a Python cgi script to kill the browser that launched it? Vagrant运行DSTK拒绝端口8080的连接 - Vagrant running DSTK refuses connections at port 8080 如何使用dtrace(或其他方法)找出Mac上ddclient的配置文件在哪里? - How can I use dtrace (or whatever) to find out where the config file is for ddclient on my mac?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM