Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find (and kill) process locking port 3000 on Mac

Tags:

macos

process

How do I find (and kill) processes that listen to/use my TCP ports? I'm on macOS.

Sometimes, after a crash or some bug, my Rails app is locking port 3000. I can't find it using ps -ef...

When running

rails server 

I get

Address already in use - bind(2) (Errno::EADDRINUSE) 

The same issue happens when stopping Node.js process. Even after the process is stopped and the app stops running, port 3000 is locked. When starting the app again, getting

Address already in use (Errno::EADDRINUSE) 
like image 490
oma Avatar asked Oct 04 '10 12:10

oma


People also ask

How do I kill a process running on port 3000 Mac?

Run the command lsof -i : (make sure to insert your port number) to find out what is running on this port. Copy the Process ID (PID) from the Terminal output. Run the command kill -9 (make sure to insert your PID) to kill the process on port.

How do I find out what is running on port 3000 Mac?

You can use lsof -i:3000 . That is "List Open Files". This gives you a list of the processes and which files and ports they use. Save this answer.


2 Answers

  1. You can try netstat

     netstat -vanp tcp | grep 3000 
  2. For macOS El Capitan and newer (or if your netstat doesn't support -p), use lsof

     lsof -i tcp:3000  
  3. For Centos 7 use:

     netstat -vanp --tcp | grep 3000 
like image 141
ghostdog74 Avatar answered Oct 14 '22 06:10

ghostdog74


Find:

sudo lsof -i :3000 

Kill:

kill -9 <PID> 

PLEASE NOTE: -9 kills the process immediately, and gives it no chance of cleaning up after itself. This may cause problems. Consider using -15 (TERM) or -3 (QUIT) for a softer termination which allows the process to clean up after itself.

like image 42
Filip Spiridonov Avatar answered Oct 14 '22 06:10

Filip Spiridonov