I face this issue alot where I need to know list of occupied ports and the pids, I keep forgetting the commands so I thought about posting them here for future references and for anyone who needs it :
I use this command to have a full detail :
sudo netstat -taupen
if I need to know exactly which one is listening on specific port (i.e. 8080) I use this :
sudo netstat -tapen | grep ":8080"
P.S: the above commands for ubuntu OS, I have not tried them on over distributions