If you get an error like [Errno 98] Address already in use when trying to run a service on a specific port in Ubuntu, you can find and free it.


Run process


inanzzz@inanzzz:/api$ mkdocs serve
[I 150813 16:22:39 server:271] Serving on http://127.0.0.1:8000

[Errno 98] Address already in use

Find and kill process


inanzzz@inanzzz:/api$ sudo netstat -lpn |grep :8000
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 5531/python

inanzzz@inanzzz:/api$ sudo kill -9 5531

Check it


inanzzz@inanzzz:/api$ sudo netstat -lpn |grep :8000
[1]+ Killed mkdocs serve

Find and kill process by name


If you wish to find a process by its name and kill it then you can use command below. Assume that your command is running as $ bin/auth in terminal.


inanzzz@inanzzz:/api$ ps aux | grep -i bin/auth | awk {'print $2'} | xargs kill -9