Skip to content

Instantly share code, notes, and snippets.

@yzhong52
Created October 30, 2020 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yzhong52/46b1640acf9f9d5caaee662eb9e1a1cf to your computer and use it in GitHub Desktop.
Save yzhong52/46b1640acf9f9d5caaee662eb9e1a1cf to your computer and use it in GitHub Desktop.
To Kill a Process Using a Port (Mac)

Put this helper funciton in your ~/.zshrc or ~/.bash_profile:

release_port() {
    pid=$(lsof -ti:$1)
    if [ -z $pid ]; then
        echo "Nothing is running on port $1"
    else
        kill $pid
        echo "Killed process on port $1 with pid $pid"
    fi
}

Use it like

release_port 3030
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment