• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What pid is using what port

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We use cloverleaf to route messages. Sometimes, for reasons as yet unknown to us, the wrong process grabs a port. Then, when the correct process tries to start, it can't have the port it wants, so it won't start. We are then left with the task of finding which PID has the port in question so we can shut it down, start the correct one, then re-start the bad one.

We're on SunOS 5.10. From what I've been able to find, "lsof" doesn't work right on this version.

The ONLY think I've found is a perl script that reads the /proc directory to get a list of every running PID. It then does a

pfiles $pid | grep AF_INET

for every PID found. We may have 1500-2000 PIDs on a machine, so this can take a while.

Does anyone have any ideas or suggestions on how I might be able to speed this up, or a different approach to take?

 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is netstat available on SunOS? On Linux, "netstat -p" lists the ports for each process.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Install sockstat, then use that: Alternatively: (drop the "u" if you don't need UDP). Use grep to filter out the port, then use a tool like awk to get the desired field(s). You may need to be root for these commands to list all the ports; sockstat doesn't recognize my MySQL server unless I use sudo, and netstat doesn't list the PID / program.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another command to base your final command on: Which leads me to this: The -t will make lsof print only the PID; the -i:<port> (or -i:<port,port,port> for multiple) filters out anything you don't need.

Again, requires root access to get any useful information.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to my research:

On Solaris 10, using "lsof -i" to show mapping of processes to TCP ports incorrectly shows all processes that have socket open as using port 65535



netstat -p returns this:

mars:hci:/opt/quovadx/qdx5.7/integrator/sitena>netstat -p
Net to Media Table: IPv4
Device IP Address Mask Flags Phys Addr
------ -------------------- --------------- ----- ---------------
ce0 ntp.mcast.net 255.255.255.255 01:00:5e:00:01:01
ce0 upwrhlab01.carenet.org 255.255.255.255 00:09:6b:dd:ab:98
ce0 medmgrdv2.carenet.org 255.255.255.255 00:04:ac:97:65:ae
ce0 cisyellow.carenet.org 255.255.255.255 00:02:55:5a:0b:d8
ce0 utschmis01.carenet.org 255.255.255.255 00:03:ba:2c:da:44
...


-l, -t, and -u are not valid flags for me.


usage: netstat [-anv] [-f address_family]
netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]
netstat -m [-v] [interval [count]]
netstat -i [-I interface] [-an] [-f address_family] [interval [count]]
netstat -r [-anv] [-f address_family|filter]
netstat -M [-ns] [-f address_family]
netstat -D [-I interface] [-f address_family]



I know next to nothing about networking, so most of this is meaningless to me.

I'll look for sockstat, and see if that might be an option.

thanks
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can mimic the -t by grepping on ^tcp; netstat -nap should help you. The following works on one of my older machines to list the details for SSH:
Combine that with awk:
$7 is the PID/program field, so the substr / index part gets the PID only, stripping off the program name. (awk uses 1 as the first index. Stupid program.)
reply
    Bookmark Topic Watch Topic
  • New Topic