hectane logo

Stop Port in Terminal

Stop running port in mac terminal

Stop Port in Terminal

I frequently encounter issues with processes occupying specific ports on macOS.

The below handy command to terminate a process occupying a port in the macOS terminal:

stop portnumber

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

To implement this, navigate to the directory and create a file named "stop" using Vim:

cd /usr/local/bin/
vim stop

Grant execution permission to the "stop" file:

chmod +x /usr/local/bin/stop

It's done. 💡

Now, restart the terminal. You can then utilize the command stop <port_number>  to terminate the process associated with the specified port.

Your setup is now complete. 🎉

Cheers ✌🏻