DEV Community

the dreaded port error "bind: address already in use", kill it!

Petry DeChamp Richardson on September 18, 2019

tl;dr: lsof -i :<PORT>, then get PID and run next command with it (be careful running this command) kill <PID>. If you want a all in o...
Collapse
 
lbonanomi profile image
lbonanomi • Edited

How about "different, not better"?

fuser -kn tcp $PORT_NUMBER will try to drop a kill -9 on any process using the specified TCP port.

Out of deference to Ben Sinclair's thoughtful counsel you can also specify a signal like this: fuser -$SIGNAL_NUMBER_OR_NAME -kn tcp $PORT_NUMBER

Collapse
 
dechamp profile image
Petry DeChamp Richardson

Tried playing around with this and read up on the man page. Seems like it doesn't know about options -k or -n (-kn). I tried variations and none worked.

Collapse
 
lbonanomi profile image
lbonanomi • Edited

How does that old joke about IT standards go, again? : \

The GNU fuser implementation from psmisc accepts -n and -k options, but distribution is far from universal.

Thread Thread
 
dechamp profile image
Petry DeChamp Richardson

ya figured that was the case lol.

Thread Thread
 
lbonanomi profile image
lbonanomi
Collapse
 
moopet profile image
Ben Sinclair

I have a better solution!

It's kill without the -9. I think that when people give that as a solution, it's like when people put sudo in front of every command in their examples, or when people recommend something like chmod -R 777 as a solution to a permissions problem.

I mean, it's probably ok, but SIGKILL is the equivalent of wrenching your USB stick out while it's in use or turning your PC off before Windows 95 says it's safe to shut down.

Collapse
 
dechamp profile image
Petry DeChamp Richardson

This is very true. I do agree with you, as to why I mentioned it's risky. The only thing I've noticed is that pretty much every time I go to kill something running on my needed port, it just won't die! ha ha. So yes, start without the -9 for sure!

Collapse
 
francisco profile image
Francisco M. Delgado

thank you so much lol