lsof

On OS X you wanna use sudo lsof -nP -iTCP -sTCP:LISTEN. The output looks like this:

$ sudo lsof -nP -iTCP -sTCP:LISTEN
COMMAND     PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd       1   root   23u  IPv6 0xf01241af1b915325      0t0  TCP *:5900 (LISTEN)
launchd       1   root   24u  IPv4 0xf01241af1b91732d      0t0  TCP *:5900 (LISTEN)
launchd       1   root   28u  IPv6 0xf01241af1b914ee5      0t0  TCP [::1]:631 (LISTEN)
launchd       1   root   29u  IPv4 0xf01241af1b916b45      0t0  TCP 127.0.0.1:631 (LISTEN)
launchd       1   root   31u  IPv6 0xf01241af1b914aa5      0t0  TCP *:22 (LISTEN)
launchd       1   root   32u  IPv4 0xf01241af1b91f32d      0t0  TCP *:22 (LISTEN)
mtmfs        55   root    4u  IPv4 0xf01241af1b91eb45      0t0  TCP 127.0.0.1:49152 (LISTEN)
mtmfs        55   root    6u  IPv4 0xf01241af1d38cb45      0t0  TCP 127.0.0.1:49153 (LISTEN)
ssh       45193 username    5u  IPv6 0xf01241af1b9128a5      0t0  TCP [::1]:8000 (LISTEN)
ssh       45193 username    6u  IPv4 0xf01241af2405eb45      0t0  TCP 127.0.0.1:8000 (LISTEN)

netstat

On many types of Linux you can use lsof, but also sudo netstat -tulpn. The output looks like this:

$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:53863           0.0.0.0:*               LISTEN      1052/rpc.statd  
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1257/mysqld     
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      969/rpcbind     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3776/apache2    
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      1972/dnsmasq    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      667/sshd        
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      773/cupsd       
tcp        0      0 0.0.0.0:50521           0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1441/master     
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      20480/3         
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      6235/11         
tcp        0      0 127.0.0.1:53698         0.0.0.0:*               LISTEN      26658/7         
udp        0      0 127.0.0.1:53            0.0.0.0:*                           1972/dnsmasq    
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1924/dhclient   
udp        0      0 0.0.0.0:111             0.0.0.0:*                           969/rpcbind     
udp        0      0 10.0.0.64:123       0.0.0.0:*                           2576/ntpd       
udp        0      0 127.0.0.1:123           0.0.0.0:*                           2576/ntpd       
udp        0      0 0.0.0.0:123             0.0.0.0:*                           2576/ntpd       
udp        0      0 0.0.0.0:713             0.0.0.0:*                           969/rpcbind     
udp        0      0 127.0.0.1:804           0.0.0.0:*                           1052/rpc.statd  
udp        0      0 0.0.0.0:42123           0.0.0.0:*                           1052/rpc.statd