Busy ports

As it often happens, you need to run a local server on a certain port. Let’s pick port number 3000 for this particular example. Sometimes, for whatever reason, that port is busy. And sure enough you will get an error, like this NodeJS one:

Error: listen EADDRINUSE

This is easily resolved with two steps.

1. Find the PID (process ID) that’s using that port:

lsof -i :3000

You will see a table containing some information, where the 2nd column is the PID we’re looking for. It’s a number basically, like 36185

2. And kill the process:

kill -9 36185

Now you can start your server or use the port the way you intended.

There are a few discussion whether to use kill -9 or kill -15, since the -15 options “gives the target process a chance to clean up after itself.” However, often it doesn’t shut the process down and you end up using -9 anyway. You can read more about that issue here.

3 thoughts on “Busy ports

      1. PHP: – Knock, knock!
        JS – Who’s there?
        PHP: – NullReferenceException!
        JS: -Too much recursion.

Comments are closed.