Kill process running on specific ports in Ubuntu and windows | Fix error “Address already in use”

Lakin Mohapatra
2 min readNov 9, 2022

Developers often face errors related to ports that are already in use on their local machines. A common error is “Address already in use (EADDRINUSE).” As beginners are not usually aware of system commands to find and kill ports, this can become difficult and lead to unnecessary frustration.

It is generally fixed in 2 ways.
Start your server on a different port. Or
Free the port by killing the process associated with it.

How to kill ports in Ubuntu

Use the below command to find process ID associated with the port.

lsof -ti :$PORT

Now kill the process ID that you obtain by running above command.

kill $(lsof -ti :$PORT)

There might be some scenarios where you have to pass SIGKILL signal to stop and kill the process immediately. Use below command.

kill -9 $(lsof -ti :$PORT)

If you have enough permission to execute above commands, please use sudo like below.

sudo kill -9 $(lsof -ti :$PORT)

Note : Replace $PORT with the port number.

How to kill ports in Windows

  1. Go to start and open the terminal in administrator mode.
  2. Run this netstat command to find what service or process is running on the desired port. Use below command.
netstat -ano | findstr $PORT

You must be getting the process ID by running above command. Now kill the process using following command.

taskkill /F /pid $PID

Note : $PID is process ID

Hope it helps developers in killing ports quickly. Thanks for reading this article. If you have any other ways of killing ports, please add them in the comments and I will update the article as per feedback.

You can connect me via Linkedin or Twitter

Sadly, Medium does not support any creator in India, if this article provided you value in some way, you can show your support to me here by clicking on the below button.

“Buy me a coffee” is a global platform where millions of people support creators and artists, financially.

Please check below article if you are struggling with a mental health issue, anxiety, depression, and are not able to focus on work.
What is Binaural Beats and How It Enhanced My Productivity Up to the Utmost Extent

--

--

Lakin Mohapatra

Software Engineer | Hungry coder | Proud Indian | Cyber Security Researcher | Blogger | Architect (web2 + web 3)