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

后端 未结 11 1710
鱼传尺愫
鱼传尺愫 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)

提交回复
热议问题