1. Andrew Hagedorn
  2. Articles
  3. Finding the Process on a Port

Finding the Process on a Port

Andrew Hagedorn, October 2020

This is an archive of the random commands I have found useful. You may or may not, but the next time I need them I will know where to find them.

As I am developing across multiple different services I will find that I want to start an application, but something else is sitting on the port. You can track what it is with this command:

function on-port {
    lsof -i TCP:$1 | grep LISTEN | awk '{print $2}'
}

Alternatively you can just blindly kill it by wrapping that up:

function kill-on-port {
    kill $(on-port $1)
}
© 2024