How can I kill whatever process is using port 8080

2019-01-21 02:56发布

On MacOSX, I'm using Packer to build a Vagrant box so I need to continually bring it up and tear it down. 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."

The solution seems simple enough: I just need to identify the process that is holding port 8080 open and kill that process, right?. It's not that easy.


If I run the command:

nmap localhost -p 8080

I receive the following 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


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


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?

7条回答
ら.Afraid
2楼-- · 2019-01-21 03:11

It can be Cisco AnyConnect. Check if /Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist exists. Then unload it with launchctl and delete from /Library/LaunchDaemons

查看更多
Animai°情兽
3楼-- · 2019-01-21 03:21

Fast and quick solution :

lsof -n -i4TCP:8080

PID is second field.

kill -9 PID

Less Fast but permanent solution

1.) Go to /usr/local/bin/ (Can use command+shift+g in finder)

2.) make file named stop. And paste 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

3.) Save file. Enjoyyy!!. Go to terminal and write stop 8888 (or any port)

U can write this command (stop port) from anywhere in directory.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-21 03:21

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

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

查看更多
5楼-- · 2019-01-21 03:21

Run: nmap -p 8080 localhost (Install nmap with MacPorts or Homebrew if you don't have it on your system yet)

Nmap scan report for localhost (127.0.0.1)

Host is up (0.00034s latency).

Other addresses for localhost (not scanned): ::1

PORT STATE SERVICE

8080/tcp open http-proxy

Run: ps -ef | grep http-proxy

UID PID PPID C STIME TTY TIME CMD

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

Run: ps -ef 640 (replace 501 with your UID)

/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

查看更多
Explosion°爆炸
6楼-- · 2019-01-21 03:25

In case above-accepted answer did not work, try below solution. You can use it for port 8080 or for any other ports.

sudo lsof -i tcp:3000 

Replace 3000 with whichever port you want. Run below command to kill that process.

sudo kill -9 PID

PID is process ID you want to kill.

Below is the output of commands on mac Terminal.

Command output

查看更多
叛逆
7楼-- · 2019-01-21 03:27

You can also use the Activity Monitor to identify and quit the process using the port.

查看更多
登录 后发表回答