New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

OS 10.5 - Find process using port


Post Reply New Thread Subscribe

 
Thread Tools
mjparme

 
Member Since: Dec 30, 2008
Posts: 14
mjparme is on a distinguished road

mjparme is offline
What are the ways to find which process is using which network port? Is there a known issue where the PID can't be found?

I have a custom written process (written in Java although shouldn't matter) which many times after exiting (but not always) its listen port is still shown as LISTEN in a netstat -an output. The process is gone though (I have exited it).

Here is a little snippet of a command-line session after the process has quit (my process listens on port 8181):

You can see that something is still listening on port 8181 because I can telnet to it.
mjparme:~:4> telnet localhost 8181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
telnet> quit
Connection closed.

However a lsof doesn't find it (a sudo lsof | grep 8181 doesn't return results either)
mjparme:~:5> sudo lsof -i TCP:8181

Nothing in ps shows that port (although the port is read from a property file rather than the command line so wouldn't really expect to see it here)
mjparme:~:6> ps auxww | grep 8181
mjparme 608 0.0 0.0 599780 392 s000 R+ 5:34PM 0:00.00 grep 8181

The netstat still shows it listening. If netstat shows it why doesn't lsof show it?
mjparme:~:7> netstat -an | grep 8181
tcp6 5 0 ::1.8181 ::1.54606 CLOSE_WAIT
tcp6 0 0 ::1.8181 ::1.54605 CLOSE_WAIT
tcp4 0 0 127.0.0.1.8181 127.0.0.1.51365 CLOSE_WAIT
tcp46 0 0 *.8181 *.* LISTEN
tcp6 0 0 ::1.54606 ::1.8181 FIN_WAIT_2
tcp6 0 0 ::1.54605 ::1.8181 FIN_WAIT_2

Some flavors of the netstat command accepts a -p option which shows the PID of the owning process, the Mac OS version doesn't appear to do that.

My main question: Is there another way to find the PID of the process that is still LISTENing on that port?

This process runs great on Windows and Linux (actually runs on Linux in production). I recently got a Mac at work so have started to do development on my Mac. (On windows on linux when the process exits that port is no longer LISTENing)

I am unsure if I am dealing with a Mac OS bug or an Apple JVM bug. Or maybe I have a coding error that is exposed in the apple JVM but not on windows or linux.
QUOTE Thanks
tichny

 
Member Since: Oct 15, 2009
Posts: 1
tichny is on a distinguished road

tichny is offline
I just had exactly the same problem as you and found a solution (at Linux / UNIX Find Out What Program / Service is Listening on a Specific TCP Port)

You can short network connections with lsof on OS X as well:
lsof -Pnl +M -i4
Grep for your port of interest and you are done.
QUOTE Thanks

Post Reply New Thread Subscribe


« 'unexpectedly quit' box appears and wont let me use the internet | Won't load past The apple logo appears with the gear thing »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Port Mapping for FTP (Airport Extreme) rickmiles Internet, Networking, and Wireless 3 09-21-2007 12:10 PM
help me convert something, please. krrose27 Switcher Hangout 4 05-25-2007 02:10 AM
How to install GCC version 4.xx???? Philipina OS X - Development and Darwin 1 04-14-2006 10:25 AM
Need creative (i.e. cheap) fix for firewire port problem mooncat Apple Notebooks 4 04-07-2005 10:54 PM
2nd port on G5 DVI problem with LCD realien Apple Desktops 0 10-22-2004 02:29 PM

All times are GMT -4. The time now is 01:33 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?