Last Updated: February 25, 2016
·
650
· dsci

Find a program that uses a specific port (OSX)

Let's say you used foreman to serve a Rails application during your development process and accidentally closed your terminal. The Ruby process is still running after you restarted your terminal application, you know the port your Rails server is running with and you want to know which PID the process is using:

lsof -i :<PORTNUMBER>
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    39207 Demo    9u  IPv4 0xf1820dff45a4ff5f      0t0  TCP *:hbci (LISTEN)