views:

47

answers:

2

How do I find processes that listens to/uses my tcp ports? I'm on mac os x. (update: 10.5 leopard)

I'm having trouble with RubyMine losing control of my rails app and getting detached from the process, locking port 3000. I can't find it using ps -ef... How do I find the stupid thing, kill it, brutally... ?

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

+1  A: 

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.

Updated thanks to Ole.

DerMike
I'm on 10.5 lepard (updated Q). I don't know if that matters here, but lsof doesn't display ports. lsof -h (lsof 4.78) is too cryptic too me...
Ole Morten Amundsen
Hmm. Don't know for sure on Leopard, but try (_as root_ -- that's important, I think) `lsof -i:3000`.
Matt Gibson
root wasn't necessary. lsof -i:3000 works too... edit your answer and put it in there. More visible. I gave you an upvote, but the answer to user#. Thanks for helping!
Ole Morten Amundsen
+2  A: 

You can try netstat

netstat -anp|grep 3000

If your netstat don't support -p, use lsof

lsof -i tcp:3000
ghostdog74
`netstat -anp` fails. `netstat: option requires an argument -- p `
Ole Morten Amundsen
`netstat -anp tcp | grep 3000` shows `tcp4 1062 0 127.0.0.1.3000 127.0.0.1.51255 ESTABLISHED` what next? 1062 is not a pid...
Ole Morten Amundsen
oh yes! you're update is correct. `lsof -i tcp:3000` nice :)
Ole Morten Amundsen