This command will show what processes are currently listening on what ports on your Ubuntu box:
sudo netstat -lntp
If you have installed nmap (
sudo apt-get install nmap), you could also run
sudo nmap -A -T4 localhost
to try and find out the name and version of the services running on each port.
The output of netstat above will give you the number of the process (pid) as well as the name. You can then use
sudo ps -f -p
to find out more about the process (for example the command line arguments passed to it) and this
sudo kill -9
to kill the process brutally (if you have no other means) and release the port in question.