macos - Find (and kill) process locking port 3000 on Mac

ID : 325

viewed : 65

Tags : macosprocessmacos

Top 5 Answer for macos - Find (and kill) process locking port 3000 on Mac

vote vote

97

  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 
vote vote

88

Find:

sudo lsof -i :3000 

Kill:

kill -9 <PID> 
vote vote

79

Quick and easiest solution:

kill -9 $(lsof -ti:3000) 

For multiple ports:

kill -9 $(lsof -ti:3000,3001) 

#3000 is the port to be freed

Kill multiple ports with single line command:

kill -9 $(lsof -ti:3000,3001) 

#here multiple ports 3000 and 3001 are the ports to be freed

lsof -ti:3000

If the prot is occupied, thie above command will return something like this: 82500 (Process ID)

lsof -ti:3001

82499

lsof -ti:3001,3000

82499 82500

kill -9 $(lsof -ti:3001,3000)

Terminates both 82499 and 82500 processes in a single command.

For using this in package.json scripts:

"scripts": {    "start": "kill -9 $(lsof -ti:3000,3001) && npm start" } 

In terminal you can use:

npm run start 
vote vote

60

Nothing above worked for me. Anyone else with my experience could try the following (worked for me):

Run:

lsof -i :3000 (where 3000 is your current port in use) 

then check status of the reported PID :

ps ax | grep <PID> 

finally, "begone with it":

kill -QUIT <PID> 
vote vote

57

A one-liner to extract the PID of the process using port 3000 and kill it.

lsof -ti:3000 | xargs kill 

The -t flag removes everything but the PID from the lsof output, making it easy to kill it.

Top 3 video Explaining macos - Find (and kill) process locking port 3000 on Mac

Related QUESTION?