Find (and kill) process locking port 3000 on Mac

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


  • You can try netstat

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

    sudo lsof -i tcp:3000 
    

  • Find:

    [sudo] lsof -i :3000
    

    Kill:

    kill -9 <PID>
    

    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>
    
    链接地址: http://www.djcxy.com/p/38838.html

    上一篇: 从窗口句柄获取自定义.NET类的组件类型

    下一篇: 在Mac上查找(并终止)进程锁定端口3000