Kill a process that occupies a port

This command lists process ids listening on a specified port:

lsof -t -i:PORT_NUMBER

You can use it to kill processes:

kill -9 (lsof -t -i:PORT_NUMBER)

Here is a Bash function making this command easier to use:

killport() { kill -9 $(lsof -t -i:$1) }

Usage example:

killport 3000