hectane logo

Stop Port in Terminal

Stop running port in mac terminal

Stop Port in Terminal

I usually face issue of something is running in the PORT in mac. 

The below handy command will help you in stopping a process running in a PORT in mac terminal. 

stop portnumber

pid=$(lsof -ti tcp:$1)
if [[ $pid ]]; then
  kill -9 $pid
  echo "Congrats!! $1 is stopped."
else
   echo "Sorry nothing running on above port" 
fi

Go to folder and open stop in vim paste the above code and save it.

cd /usr/local/bin/
vim stop

Then give permission to stop file 

chmod +x /usr/local/bin/stop

It's done. 💡

Then restart terminal and you can use the stop <port> command and it will stop the process running in that port. 🔨

Cheers ✌🏻