How can I kill whatever process is using port 8080 so that I can vagrant up?

后端 未结 11 1707
鱼传尺愫
鱼传尺愫 2020-12-07 07:13

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

相关标签:
11条回答
  • 2020-12-07 08:00

    Fast and quick solution:

    lsof -n -i4TCP:8080

    PID is the second field. 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)

    2. Make a file named 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
    3. Now, go to terminal and write stop 8888 (or any port)
    0 讨论(0)
  • 2020-12-07 08:03

    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

    0 讨论(0)
  • 2020-12-07 08:06

    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.

    0 讨论(0)
  • 2020-12-07 08:06

    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.

    0 讨论(0)
  • 2020-12-07 08:07
    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.

    0 讨论(0)
提交回复
热议问题