Skip to content

Port Already in Use

This operation is to free a selected port already in use. A simple alternative is to start your app on a different port but in this case we will see how to free up the port your app wants to use.

Terminal window
sudo lsof -i :8000 # find process + PID on port 8000
sudo ss -ltnp | grep 8000 # alternative
sudo fuser 8000/tcp # one-shot: just print the PID
sudo fuser -k 8000/tcp # one-shot: find and kill in one step
kill <PID> # stop the process
kill -9 <PID> # force-kill if it ignores kill

Running ss or lsof without sudo shows the port is occupied but hides the PID and process name. You need elevated privileges to see which process owns the socket.

Terminal window
sudo ss -ltnp | grep 8000
sudo lsof -i :8000

The output will show the process name (e.g. python, uvicorn, docker-proxy) and the PID.

Terminal window
kill <PID>
kill -9 <PID> # if the process ignores the first kill

fuser skips the find then kill two step run:

Terminal window
sudo fuser 8000/tcp # print PID only
sudo fuser -k 8000/tcp # kill it directly