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)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
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.
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
.
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.