Mac Netstat with PID

On a Mac to list processes and the ports that are listening on, type the following into a terminal window:

sudo lsof -i -P