Find (and kill) process locking port 3000 on Mac

2019-01-02 16:10发布

How do I find processes that listens to/uses my tcp ports? I'm on mac os x.

Sometimes, after a crash or some bug, my rails app is locking port 3000. I can't find it using ps -ef... How do I find the stupid thing and kill it, brutally... ?

When doing

rails server

I get

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

2014 update:

To complete some of the answers below: After executing the kill commands, deleting the pid file might be necessary rm ~/mypath/myrailsapp/tmp/pids/server.pid

标签: macos process
24条回答
步步皆殇っ
2楼-- · 2019-01-02 16:57

Using sindresorhus's fkill tool, you can do this:

$ fkill :3000
查看更多
何处买醉
3楼-- · 2019-01-02 16:58

Step 1: Find server which are running: ps aux | grep puma Step 2: Kill those server Kill -9 [server number]

查看更多
孤独总比滥情好
4楼-- · 2019-01-02 16:59

In your .bash_profile, create a shortcut for terminate the 3000 process:

terminate(){
  lsof -P | grep ':3000' | awk '{print $2}' | xargs kill -9 
}

Then, call $terminate if it's blocked.

查看更多
泪湿衣
5楼-- · 2019-01-02 16:59

This single command line is easy to remember:

npx kill-port 3000

For a more powerful tool with search:

npx fkill-cli


PS: They use third party javascript packages

Sources: tweet | github

查看更多
看淡一切
6楼-- · 2019-01-02 16:59

Find the open connection

lsof -i -P | grep -i "listen"

Kill by process ID

kill -9 'PID'

查看更多
梦寄多情
7楼-- · 2019-01-02 17:05

To view the processes blocking the port:

netstat -vanp tcp | grep 3000

To Kill the processes blocking the port:

kill $(lsof -t -i :3000)

查看更多
登录 后发表回答