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
lsof -n -i4TCP:8080
PID
is the second field. Then, kill that process:
kill -9 PID
Go to /usr/local/bin/
(Can use command+shift+g in finder)
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
chmod 755 stop
stop 8888
(or any port)